google.load和谷歌应用程序脚本

时间:2013-10-09 16:00:03

标签: javascript google-apps-script google-sites jsapi

我正在尝试使用谷歌应用程序脚本向Google网站添加可视化效果,但我仍然在文件'代码'中出现语法错误,尽管直接从谷歌图表的开发者页面复制了它。代码如下。这是线  google.load('visualization','1',{'packages':['motionchart']}); 一直在打破。我假设它没有找到库,但我无法弄清楚如何修复它。我可以不在应用脚本中使用它吗?

<html>
<head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load('visualization', '1', {'packages':['motionchart']});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Fruit');
        data.addColumn('date', 'Date');
        data.addColumn('number', 'Sales');
        data.addColumn('number', 'Expenses');
        data.addColumn('string', 'Location');
        data.addRows([
          ['Apples',  new Date (1988,0,1), 1000, 300, 'East'],
          ['Oranges', new Date (1988,0,1), 1150, 200, 'West'],
          ['Bananas', new Date (1988,0,1), 300,  250, 'West'],
          ['Apples',  new Date (1989,6,1), 1200, 400, 'East'],
          ['Oranges', new Date (1989,6,1), 750,  150, 'West'],
          ['Bananas', new Date (1989,6,1), 788,  617, 'West']
        ]);
        var chart = new 

google.visualization.MotionChart(document.getElementById('chart_div'));
            chart.draw(data, {width: 600, height:300});
          }
        </script>
      </head>

      <body>
        <div id="chart_div" style="width: 600px; height: 300px;"></div>
      </body>
    </html>

2 个答案:

答案 0 :(得分:2)

由于与caja相关的问题,您无法在应用脚本中使用这些库。如果您查看应用程序脚本问题页面,您将看到更多信息,因为存在问题。见https://code.google.com/p/google-apps-script-issues/issues/detail?id=2949

答案 1 :(得分:0)

这个例子现在确实有效。

看起来它是在3月中旬之后的某个时间逐渐推出的,基于50分钟左右Google Apps Unscripted - March 2014所说的内容。

相关问题