0

I'm trying to add visualizations to a google site using google apps script, but I keep getting a syntax error for file 'code' despite having copied it directly from the developers page for google charts. The code is below. it's the line google.load('visualization', '1', {'packages':['motionchart']}); that keeps breaking. I'm assuming it's not finding the library, but I can't figure out how to fix it. Can I not use this in apps script?

<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 Answers2

2

You cant use those libraries in apps script because of caja-related issues. If you look at the apps script issues page you will see more info as there is an issue logged there. See https://code.google.com/p/google-apps-script-issues/issues/detail?id=2949

Zig Mandel
  • 19,571
  • 5
  • 26
  • 36
0

This example does work these days.

It looks like it was gradually rolled out sometime after mid-March, based upon what was said in Google Apps Unscripted - March 2014 around minute 50.

Nexus
  • 106
  • 1
  • 3