使用Cloudformatter将Google Chart导出为PDF,生成空白PDF

问题描述 投票:1回答:1

我正在尝试将谷歌图表导出到PDF文件。我正在使用cloudformatter.com上的xepOnline.jqPlugin.js插件。我遵循了http://www.cloudformatter.com/CSS2Pdf.APIDoc.Usage的所有步骤

但是当我尝试导出时,PDF会生成空白方框。

enter image description here

我正在从jquery ajax调用加载谷歌图表。任何人都可以告诉我这可能是什么问题吗?

这是一个没有ajax调用的示例代码 -

 <button type="button" id="" class="btn btn-success pull-right" style="margin-right: 7px;" onclick="return xepOnline.Formatter.Format('chart_container', {render: 'download', filename: 'Years_Build', mimeType: 'application/pdf'});">Export</button>
    <div id="chart_container">
      <div id="chart_div"></div>
    </div>
<script type="text/javascript">
function drawChart() {
var data = google.visualization.arrayToDataTable([
          ['Year', 'Sales', 'Expenses', 'Profit'],
          ['2014', 1000, 400, 200],
          ['2015', 1170, 460, 250],
          ['2016', 660, 1120, 300],
          ['2017', 1030, 540, 350]
        ]);

        var options = {
          chart: {
            title: 'Company Performance',
            subtitle: 'Sales, Expenses, and Profit: 2014-2017',
          }
        };

        var chart = new google.charts.Bar(document.getElementById('chart_div'));
        chart.draw(data, google.charts.Bar.convertOptions(options));
                                                            }
google.charts.load('current', {'packages': ['bar']});
google.charts.setOnLoadCallback(drawChart);
</script>
jquery pdf google-chartwrapper css-to-pdf
1个回答
2
投票

您缺少需要添加的SVG名称空间。如果您在每个图表的网站上检查样本小提琴,您将看到一个在绘制图表后添加名称空间的函数。

例如,请参阅http://jsfiddle.net/w1rpjxoe/

你会看到这个功能:

function AddNamespace(){
  var svg = jQuery('#chart_div svg');
  svg.attr("xmlns", "http://www.w3.org/2000/svg");
  svg.css('overflow','visible');
}

它是从这个监听器调用的:

 google.visualization.events.addListener(chart, 'ready', AddNamespace);

这样做是将缺少的SVG名称空间添加到Google图表不能执行的图表SVG中,但是@cloudformatter需要。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.