未捕获的语法错误:意外的令牌&

时间:2014-03-03 03:44:23

标签: javascript python google-visualization jinja2

我正在尝试发送一些我在python代码中收集的数据。这是我的python代码与此问题相关 -

query = "SELECT USState, NOFU2008 FROM " + TABLE_ID 
        data2008 = service.query().sql(sql=query).execute()
        print data2008['columns']
        query = "SELECT USState, NOFU2009 FROM " + TABLE_ID 
        data2009 = service.query().sql(sql=query).execute()
        # print data2009
        query = "SELECT USState, NOFU2010 FROM " + TABLE_ID 
        data2010 = service.query().sql(sql=query).execute()

        variables = {"data2008": data2008 , "data2009": data2009, "data2010": data2010}
        print variables["data2009"]
        self.render_response('index.html', variables)

这是我的html-javascript代码 -

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

    function drawMap() {
        console.log("In draw map function")
      var test = {{data2008}}
      console.log(test)
      var data = google.visualization.arrayToDataTable([
        ['State', 'No of Users'],
        ['US-PA', 200],
        ['US-CA', 300],
        ['US-NY', 400],
        ['US-TX', 500],
        ['US-SC', 600],
        ['US-MD', 700]
      ]);

      var options = {};
      options['region'] = 'US'
      options['dataMode'] = 'regions';

      var container = document.getElementById('map_canvas');
      var geomap = new google.visualization.GeoMap(container);
      geomap.draw(data, options);
  };
  </script>
</head>

<body>
  <div id='map_canvas'></div>
</body>

</html>

注意 - 我目前只输入了地图部分的虚拟值。但我想在测试变量中看到我的数据。但那里有一些问题。这是我在浏览器控制台上可以看到的内容 -

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

    function drawMap() {
        console.log("In draw map function")
      var test = {u&#39;rows&#39;: [[u&#39;Alabama&#39;, 290060.0], [u&#39;Alaska&#39;, 46400.0], [u&#39;Arizona&#39;, 320320.0], [u&#39;Arkansas&#39;, 295280.0], [u&#39;California&#39;, 2524680.0], [u&#39;Colorado&#39;, 412240.0], [u&#39;Connecticut&#39;, 441260.0], [u&#39;Delaware&#39;, 48840.0], [u&#39;District of Columbia&#39;, 334100.0], [u&#39;Florida&#39;, 1488580.0], [u&#39;Georgia&#39;, 912880.0], [u&#39;Hawaii&#39;, 91720.0], [u&#39;Idaho&#39;, 69920.0], [u&#39;Illinois&#39;, 1470320.0], [u&#39;Indiana&#39;, 445600.0], [u&#39;Iowa&#39;, 265640.0], [u&#39;Kansas&#39;, 331280.0], [u&#39;Kentucky&#39;, 294680.0], [u&#39;Louisiana&#39;, 264600.0], [u&#39;Maine&#39;, 136700.0], [u&#39;Maryland&#39;, 548040.0], [u&#39;Massachusetts&#39;, 950880.0], [u&#39;Michigan&#39;, 938200.0], [u&#39;Minnesota&#39;, 637340.0], [u&#39;Mississippi&#39;, 175360.0], [u&#39;Missouri&#39;, 732160.0], [u&#39;Montana&#39;, 53000.0], [u&#39;Nebraska&#39;, 197380.0], [u&#39;Nevada&#39;, 100900.0], [u&#39;New Hampshire&#39;, 150620.0], [u&#39;New Jersey&#39;, 1034520.0], [u&#39;New Mexico&#39;, 57500.0], [u&#39;New York&#39;, 2204280.0], [u&#39;North Carolina&#39;, 767300.0], [u&#39;North Dakota&#39;, 64250.0], [u&#39;Ohio&#39;, 953020.0], [u&#39;Oklahoma&#39;, 222520.0], [u&#39;Oregon&#39;, 242500.0], [u&#39;Pennsylvania&#39;, 1189260.0], [u&#39;Rhode Island&#39;, 133820.0], [u&#39;South Carolina&#39;, 311900.0], [u&#39;South Dakota&#39;, 124680.0], [u&#39;Tennessee&#39;, 469280.0], [u&#39;Texas&#39;, 1586920.0], [u&#39;Utah&#39;, 217240.0], [u&#39;Vermont&#39;, 71360.0], [u&#39;Virginia&#39;, 855700.0], [u&#39;Washington&#39;, 523260.0], [u&#39;West Virginia&#39;, 82940.0], [u&#39;Wisconsin&#39;, 628840.0], [u&#39;Wyoming&#39;, 31420.0]], u&#39;kind&#39;: u&#39;fusiontables#sqlresponse&#39;, u&#39;columns&#39;: [u&#39;USState&#39;, u&#39;NOFU2008&#39;]}
      console.log(test)
      var data = google.visualization.arrayToDataTable([
        ['State', 'No of Users'],
        ['US-PA', 200],
        ['US-CA', 300],
        ['US-NY', 400],
        ['US-TX', 500],
        ['US-SC', 600],
        ['US-MD', 700]
      ]);

      var options = {};
      options['region'] = 'US'
      options['dataMode'] = 'regions';

      var container = document.getElementById('map_canvas');
      var geomap = new google.visualization.GeoMap(container);
      geomap.draw(data, options);
  };
  </script>
</head>

<body>
  <div id='map_canvas'></div>
</body>

</html>

如果我想在地图中为2008年的每个州插入值,我应该做出哪些更改?

0 个答案:

没有答案