【问题标题】:jqplot html not rendering properly in new windowjqplot html 在新窗口中无法正确呈现
【发布时间】:2012-03-17 11:34:17
【问题描述】:

我有一个应用程序,它使用 jqplot 来生成一些图表,我希望能够打印图表,并且只打印图表。

所以我写了一个函数,一个简单的函数,它打开一个新窗口,其中包含应用程序主页中 graphdiv 中的代码。我的问题是图表无法在新窗口中正确显示。有什么想法吗??

function newwindow() {

    var windowObject = window.open('', 'windowObject', 'arguments...');
    windowObject.document.write("<html> <head><link rel='stylesheet' type='text/css' href='jquery.jqplot.css' /></head> <body onload=''><div class='jqplot-target'>" + $('#chartdiv').html() + "</div></body></html>");
    windowObject.document.close();


}

谢谢。

【问题讨论】:

  • “显示不正确”是什么意思?从代码看来,您正在从先前渲染的绘图中获取 html 并将其扔到您的新窗口中。我认为这只会让你得到画布元素,而不是画布上绘制的内容。看到这个问题:stackoverflow.com/questions/3318565/…
  • 马克,我认为这是正确的。我正在抓取先前渲染的情节的 html,假设这会复制所有内容。

标签: javascript jquery html jqplot


【解决方案1】:

创建一个这样的函数,这样打开的图像就会有一个dataUrl。

var img = $('#chartdiv').jqplotToImage(50, 0);
  if (img) {
    open(img.toDataURL("image/png"));
  } 

这个jqplot to image可以在这个链接中找到 https://github.com/lsiden/export-jqplot-to-png

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-29
    • 1970-01-01
    • 2012-08-23
    • 1970-01-01
    相关资源
    最近更新 更多