admin管理员组文章数量:1327661
I am trying to construct google charts
using a ajax
response form PHP
file. Following is the output of alert
in my javascript
{"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.
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
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
{"totalclientstatus":"{\"cols\":[{\"id\":\"5\",\"label\":\"LISTING\",\"type\":\"number\"}],\"rows\":[{\"c\":[{\"v\":\"1\"}]}]}"}
I am trying to construct google charts
using a ajax
response form PHP
file. Following is the output of alert
in my javascript
{"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.
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
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
{"totalclientstatus":"{\"cols\":[{\"id\":\"5\",\"label\":\"LISTING\",\"type\":\"number\"}],\"rows\":[{\"c\":[{\"v\":\"1\"}]}]}"}
Share
Improve this question
edited Sep 26, 2012 at 1:52
Deepak
asked Sep 26, 2012 at 1:39
DeepakDeepak
6,81218 gold badges70 silver badges121 bronze badges
2
-
Are you using
google.setOnLoadCallback
? – McGarnagle Commented Sep 26, 2012 at 1:47 -
yes i am using that to call the ajax and the ajax in turn calls the
drawBarChartAll()
– Deepak Commented Sep 26, 2012 at 1:50
1 Answer
Reset to default 9I guess you missed the 'new' :
var data = new google.visualization.DataTable( ...
本文标签: phpJSON to Google ChartsStack Overflow
版权声明:本文标题:php - JSON to Google Charts - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742230176a2437077.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论