0
我試圖創建一些基於每週的no.of.success和no.of.failure status.i創建了谷歌折線圖選項的圖表,但它試圖從數據庫中獲取值時不起作用。使用谷歌圖表使用PHP和MySQL創建圖表?
我的表名是:細節
代碼如下:
$sql_no=mysql_query("SELECT COUNT(*) AS nof FROM details WHERE result=1");
$call=mysql_fetch_assoc($sql_no);
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Month');
data.addColumn('number', 'Success');
data.addColumn('number', 'Failure');
<?php $results = array();
while ($row = mysql_fetch_assoc($sql_no)){
$num=$results[$row['nof']];
}
echo 'data.addRows('.count($results).');';
$i = 0;
foreach ($results as $value => $num){
echo'
data.setValue('.$i.', 0, "'.$value.'");
data.setValue('.$i.', 1, '.$num.');
';
$i++;
}
?> var options = {
width: 800, height: 340,
title: 'Call details'
};
var chart =
new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}