1

我有一个网页,它使用 jqplot 绘制图表,使用 Google Datatable 以表格格式显示数据。我在网页中还有一个“导出”超链接,用于生成网页的 PDF 副本以供下载。我的导出代码如下所示:

function exportPDF() {
    var img = $('#clicks_chart_div').jqplotToImage(0, 0); 
    if (img) {
        var imgTag = $('<img id="ccanvasimage">');
        imgTag.attr('src', img.toDataURL("image/png"));
        imgTag.attr('width', 450);
        imgTag.attr('height', 320);
        $('#clicks_chart_div').replaceWith(imgTag);
    } else {
        alert('could not get image');
    }
    $('#src').val(document.documentElement.innerHTML);
    $('#frmSource').submit();
  }

此代码在浏览器中运行良好并下载相应的 PDF。但是,当我通过 HTMLUnit 调用同一页面时,调用“var img = $('#clicks_chart_div').jqplotToImage(0, 0);” 无法生成图像并转到其他部分“警报('无法获取图像');” 因此,生成的 PDF 仅包含数据表而不包含任何图表。

关于为什么调用 jqplotToImage 失败的任何想法?FWIW,jqplotToImage 的代码通过外部脚本包含如下:

<script language="javascript" type="text/javascript" src="javascripts/export-jqplot-to-png.js"></script>

谢谢。

4

0 回答 0