[英]JSON to Google Charts
I am trying to construct google charts
using a ajax
response form PHP
file. 我正在尝试使用
ajax
响应表PHP
文件构造google charts
。 Following is the output of alert
in my javascript
以下是我的
javascript
中alert
的输出
{"cols":[{"id":"5","label":"LISTING","type":"number"}],"rows":[{"c":[{"v":"1"}]}]}
When I used the following code to construct the graph i get the error Data table is not defined.
当我使用以下代码构造图形时,出现错误
Data table is not defined.
function drawBarChartAll(totalclientstatus) {
alert(totalclientstatus);
//eval ( 'var jsonobject = totalclientstatus;');
//var json = google.visualization.DataTable.toJSON(totalclientstatus)
var data = google.visualization.DataTable(totalclientstatus);
var options = {
'width':670,
'height':310,
hAxis: {title: 'Year', titleTextStyle: {color: 'red'}}
//chartArea:{left:20,top:20,width:"70%",height:"100%"}
};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.ColumnChart(document.getElementById('barchartall'));
chart.draw(data, options);
}
What am i doing wrong ? 我究竟做错了什么 ? I am using the following
php
to construct the JSON
我正在使用以下
php
构造JSON
while ($row = mysqli_fetch_array($agent_result, MYSQL_ASSOC))
{
$columns = array();
$reports['cols'][] = array(id => "{$row['statusid']}"
, label => "{$row['status']}"
, type => "number");
$columns['c'][] = array(v => $row['total']);
$reports['rows'][] = $columns;
}
return json_encode($reports);
The ajax
response is ajax
响应是
{"totalclientstatus":"{\"cols\":[{\"id\":\"5\",\"label\":\"LISTING\",\"type\":\"number\"}],\"rows\":[{\"c\":[{\"v\":\"1\"}]}]}"}
I guess you missed the 'new' : 我想你错过了“新”:
var data = new google.visualization.DataTable( ...
var data = new google.visualization.DataTable(...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.