Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过Javascript以编程方式将动态图打印到打印机_Javascript_C#_Asp.net_Printing_Dygraphs - Fatal编程技术网

通过Javascript以编程方式将动态图打印到打印机

通过Javascript以编程方式将动态图打印到打印机,javascript,c#,asp.net,printing,dygraphs,Javascript,C#,Asp.net,Printing,Dygraphs,我目前正在一个Asp.net网站上工作,该网站的C#代码落后,试图通过javascript在打印机上以编程方式打印动态图表。当我试图打印包含动态图的DIV时,我只能打印图表的x轴和y轴;纸上没有图表 后来,我发现了一篇关于StackOverflow()的文章,其中有人试图做同样的事情,他们收到的建议是尝试使用Dygraph.export.asPNG函数中内置的Dygraph,该函数包含在Dygraph-extra.js文件中,将Dygraph转换为PNG图像,然后在打印机上打印出来。我也试过了,

我目前正在一个Asp.net网站上工作,该网站的C#代码落后,试图通过javascript在打印机上以编程方式打印动态图表。当我试图打印包含动态图的DIV时,我只能打印图表的x轴和y轴;纸上没有图表

后来,我发现了一篇关于StackOverflow()的文章,其中有人试图做同样的事情,他们收到的建议是尝试使用Dygraph.export.asPNG函数中内置的Dygraph,该函数包含在Dygraph-extra.js文件中,将Dygraph转换为PNG图像,然后在打印机上打印出来。我也试过了,我能打印出来的只是一个代表动态图的小正方形图标。我不确定我做错了什么。这是我的密码:

var graph = null;
var row1 = null;
var options = {
            labels: row1,
            labelsDivStyles: {
                        'text-align': 'center',
                        'background': 'white',
                        'font-size': '12px',
                        'color': 'black
                    },  //labelsDivStyles
            'colors': ['red', 'orange', 'green', 'blue'],
            labelsSeperateLines: true,
            labelsDiv: "labels",
            legend: 'always',
            title: 'Temperature vs. Time',
            titleHeight: 18,
            ylabel: 'Temperature (c)',
            xlabel: 'Time',
            axes: {
                x:{
                    axisLabelFontSize: 12,
                    axisLabelColor: 'black',
                    axisLineColor: 'black',
                    gridLineWidth: 2,
                    drawGrid: true,
                    drawAxis: true
                },//x
                y:{
                    axisLabelFontSize: 12,
                    axisLabelColor: 'black',
                    axisLineColor: 'black',
                    gridLineWidth: 2,
                    drawGrid: true,
                    drawAxis: true,
                    independentTicks: true
                }//y
            }//axes


        };

var drawGraph = function(data){
    var arry = toArray(data);
    var firstRow = arr[0];
    row1 = firstRow;
    var data = arry.slice(1); //Remove first element (labels);
    var img = document.getElementById(“DygraphDiv”);
    return new Dygraph(img, data, options);

}


function graphTemps(){

    var stringData = FetchDataFromDatabase();
    graph = drawGraph(stringData);
}

function printGraph(){
    //Create the image 
    var img = document.getElementById(“DygraphDiv”);
    Dygraph.export.asPNG(graph, img, options); 

    //Print the Dygraph image on a printer
    var printWindow = window.open('', '', 'height=300,width=600');
    printWindow.document.write('<html><head><title>Graph DIV Contents</title>');
    printWindow.document.write('<head><body>');
    printWindow.document.write("<img src=" + img + ">");
    printWindow.document.write('</body></html>');
    printWindow.doucment.close();

}
var图=null;
var row1=null;
变量选项={
标签:第1行,
标签样式:{
“文本对齐”:“居中”,
“背景”:“白色”,
“字体大小”:“12px”,
“颜色”:“黑色”
},//标签样式
“颜色”:[“红色”、“橙色”、“绿色”、“蓝色”],
标签分离线:正确,
labelsDiv:“标签”,
传说:“永远”,
标题:“温度与时间”,
标题:18,
ylabel:“温度(c)”,
xlabel:“时间”,
轴线:{
x:{
axisLabelFontSize:12,
axisLabelColor:'黑色',
axisLineColor:'黑色',
网格线宽度:2,
是的,
drawAxis:对
},//x
y:{
axisLabelFontSize:12,
axisLabelColor:'黑色',
axisLineColor:'黑色',
网格线宽度:2,
是的,
是的,
独立滴答声:对
}//y
}//斧头
};
var drawGraph=函数(数据){
var arry=toArray(数据);
var firstRow=arr[0];
第1行=第一行;
var data=arry.slice(1);//删除第一个元素(标签);
var img=document.getElementById(“DygraphDiv”);
返回新的动态图(img、数据、选项);
}
函数graphTemps(){
var stringData=FetchDataFromDatabase();
图形=绘图图形(stringData);
}
函数printGraph(){
//创建图像
var img=document.getElementById(“DygraphDiv”);
export.asPNG(图形、img、选项);
//在打印机上打印动态图像
变量printWindow=window.open(“”,’高度=300,宽度=600’);
printWindow.document.write('Graph DIV Contents');
printWindow.document.write(“”);
printWindow.document.write(“”);
printWindow.document.write(“”);
printWindow.doucment.close();
}