有没有人用过google chart api 折线图,把php里的数组放到js里显示折线图
<?php
$json =json_encode($myData['CourseInfo']);
?>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var json = <?php echo $json?>;
var data = new google.visualization.DataTable();
data.addColumn('string', 'day');
data.addColumn('number', '长期数量');
data.addColumn('number', '非长期数量');
var cnt = json.length;
var arr=new Array();
for(i=0;i<cnt;i++){
var j='\''+json[i]['tdate']+'\'';
var x = json[i]['coulong'];
var y = json[i]['coulongun'];
arr[i] = '[' + j + ',' +x+','+ y+']';
}
alert(arr);弹出(['2012-03-27',0,119],['2012-03-26',0,335],['2012-03-25',0,539],['2012-03-24',0,534],['2012-03-23',0,344],['2012-03-22',0,335],['2012-03-21',0,343],['2012-03-20',0,301])
date.addRows([arr]);这样折线图不会显示出来
// data.addRows([
// ['2012-03-27',0,119],['2012-03-26',0,335],['2012-03-25',0,539],['2012-03-24',0,534],['2012-03-23',0,344],['2012-03-22',0,335],['2012-03-21',0,343],['2012-03-20',0,301]
// ]);这样折线图会显示出来
var options = {
title: '监控'
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
我是把php数组转为json数据,把json数据放到data.addRows([])这里,但是不显示,求解
[解决办法]
给你发过去了,看看吧