Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 数据格式对google可视化无效_Python_Json_Google Visualization - Fatal编程技术网

Python 数据格式对google可视化无效

Python 数据格式对google可视化无效,python,json,google-visualization,Python,Json,Google Visualization,我试图将一些数据可视化为一个简单的条形图。我用python获取数据并将其发送到客户端。这是它的python代码- query_string = 'SELECT state, count(*) FROM [{0}] GROUP by state;'.format(_DATABASE_NAME) births = self.run_query(query_string, filename='data/states.json') outcome = [] for row in births: a

我试图将一些数据可视化为一个简单的条形图。我用python获取数据并将其发送到客户端。这是它的python代码-

query_string = 'SELECT state, count(*) FROM [{0}] GROUP by state;'.format(_DATABASE_NAME)
births = self.run_query(query_string, filename='data/states.json')
outcome = []
for row in births:
   age = row['mother_age']
   times = row['f0_']
   ip = {'age': int(age), 'times': int(times)}
   outcome = outcome + [ip]
outcome.insert(0, ('Age', 'No of occurunces'))
logging.info(json.encode(outcome))
这就是我在日志文件中看到的-

[["Age","No of occurunces"],{"age":31,"times":6170247},{"age":30,"times":6876756},{"age":26,"times":8271245},..........]
这是index.html文件-

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

    function drawMap() {
  // Create and populate the data table.
  var data = google.visualization.arrayToDataTable({{times|safe}});

  // Create and draw the visualization.
  new google.visualization.BarChart(document.getElementById('visualization')).
      draw(data,
           {title:"Yearly Coffee Consumption by Country",
            width:600, height:400,
            vAxis: {title: "Year"},
            hAxis: {title: "Cups"}}
      );
}

  </script>
</head>

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

</body>

</html>

我的代码有什么问题?

您必须准备一个没有属性名的数组数组。这行
ip={'age':int(age),'times':int(times)}
应该更改。@AntoJurković-我试过这么做。这个问题仍然存在。更确切地说,我这样做了-ip=[int(age),int(times)]当您使用
ip=[int(age),int(times)]
时,您的代码输出什么?
function drawVisualization() {
  // Create and populate the data table.
  var data = google.visualization.arrayToDataTable([
    ['Year', 'Austria'],
    ['2003',  1336060],
    ['2004',  1538156],
    ['2005',  1576579],
    ['2006',  1600652],
    ['2007',  1968113],
    ['2008',  1901067]
  ]);

  // Create and draw the visualization.
  new google.visualization.BarChart(document.getElementById('visualization')).
      draw(data,
           {title:"Yearly Coffee Consumption by Country",
            width:600, height:400,
            vAxis: {title: "Year"},
            hAxis: {title: "Cups"}}
      );
}
​