我正在尝试发送一些我在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'rows': [[u'Alabama', 290060.0], [u'Alaska', 46400.0], [u'Arizona', 320320.0], [u'Arkansas', 295280.0], [u'California', 2524680.0], [u'Colorado', 412240.0], [u'Connecticut', 441260.0], [u'Delaware', 48840.0], [u'District of Columbia', 334100.0], [u'Florida', 1488580.0], [u'Georgia', 912880.0], [u'Hawaii', 91720.0], [u'Idaho', 69920.0], [u'Illinois', 1470320.0], [u'Indiana', 445600.0], [u'Iowa', 265640.0], [u'Kansas', 331280.0], [u'Kentucky', 294680.0], [u'Louisiana', 264600.0], [u'Maine', 136700.0], [u'Maryland', 548040.0], [u'Massachusetts', 950880.0], [u'Michigan', 938200.0], [u'Minnesota', 637340.0], [u'Mississippi', 175360.0], [u'Missouri', 732160.0], [u'Montana', 53000.0], [u'Nebraska', 197380.0], [u'Nevada', 100900.0], [u'New Hampshire', 150620.0], [u'New Jersey', 1034520.0], [u'New Mexico', 57500.0], [u'New York', 2204280.0], [u'North Carolina', 767300.0], [u'North Dakota', 64250.0], [u'Ohio', 953020.0], [u'Oklahoma', 222520.0], [u'Oregon', 242500.0], [u'Pennsylvania', 1189260.0], [u'Rhode Island', 133820.0], [u'South Carolina', 311900.0], [u'South Dakota', 124680.0], [u'Tennessee', 469280.0], [u'Texas', 1586920.0], [u'Utah', 217240.0], [u'Vermont', 71360.0], [u'Virginia', 855700.0], [u'Washington', 523260.0], [u'West Virginia', 82940.0], [u'Wisconsin', 628840.0], [u'Wyoming', 31420.0]], u'kind': u'fusiontables#sqlresponse', u'columns': [u'USState', u'NOFU2008']}
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年的每个州插入值,我应该做出哪些更改?