我正在尝试google charts
使用ajax
响应表单PHP
文件进行构建。以下是alert
我的输出javascript
{"cols":[{"id":"5","label":"LISTING","type":"number"}],"rows":[{"c":[{"v":"1"}]}]}
当我使用以下代码构建图表时,我得到了错误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);
}
我究竟做错了什么 ?我正在使用以下内容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);
ajax
回应是
{"totalclientstatus":"{\"cols\":[{\"id\":\"5\",\"label\":\"LISTING\",\"type\":\"number\"}],\"rows\":[{\"c\":[{\"v\":\"1\"}]}]}"}