使用Google Chart库保存图像时出现无法解释的Javascript错误

时间:2015-02-02 18:31:54

标签: javascript html google-chartwrapper

我使用谷歌图表创建了一个基本的组织结构图。我现在正在尝试添加代码以将其另存为图像。 Google自己的示例工作正常(https://developers.google.com/chart/interactive/docs/printing),但由于某种原因,我的代码报告了一个未捕获的TypeError:undefined不是函数错误。由于我的代码与Google的示例相同,我不知道导致错误的原因。

<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["orgchart"]});
      google.setOnLoadCallback(drawChart);


      function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Name');
        data.addColumn('string', 'Manager');
        data.addColumn('string', 'ToolTip');

        data.addRows([
          [{v:'1', f:'Robin A<div style="color:red; font-style:italic">Manager</div>'}, '', ''],
[{v:'2', f:'Peter B<div style="color:red; font-style:italic">Line Mgr</div>'}, '1', ''],
[{v:'3', f:'Paul C<div style="color:red; font-style:italic">Worker</div>'}, '1', ''],
[{v:'4', f:'Mark D<div style="color:red; font-style:italic">Worker</div>'}, '2', ''],
[{v:'5', f:'Kim E<div style="color:red; font-style:italic">Worker</div>'}, '2', '']
        ]);

        var chart_div = document.getElementById('chart_div');
        var chart = new google.visualization.OrgChart(chart_div);


        // Wait for the chart to finish drawing before calling the getImageURI() method.
      google.visualization.events.addListener(chart, 'ready', function () {
        chart_div.innerHTML = '<img src="' + chart.getImageURI() + '">';
        console.log(chart_div.innerHTML);
      });


        chart.draw(data, {allowHtml:true});
        document.getElementById('png').outerHTML = '<a href="' + chart.getImageURI() + '">Printable version</a>';
      }


   </script>
    </head>
  <body>
    <div id="png"></div>
    <div id="chart_div"></div>
  </body>
</html>

0 个答案:

没有答案