3
請問您可以在這裏幫忙。下面是我使用來獲取MYSQL數據並傳遞到谷歌圖在PHP中加載mysql數據到谷歌圖表
$result = DB_query($sql, '', '', False, False);
$table = array();
$table['cols'] = array(
array('label' => 'col1', 'type' => 'string'),
array('label' => 'col2', 'type' => 'int')
);
$rows = array();
while($r = mysqli_fetch_assoc($result)) {
$temp = array();
// the following line will be used to slice the Pie chart
$temp[] = array('v' => (string) $r['col1']);
// Values of each slice
$temp[] = array('v' => (int) $r['col2']);
$rows[] = array('c' => $temp);
}
下面的腳本是JS部分
echo
'
<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 data = new google.visualization.DataTable(',$jsonTable,');
var options = {
title: "My Weekly Plan",
is3D: "true",
width: 800,
height: 600
};
var chart = new google.visualization.PieChart(document.getElementById("chart_div"));
chart.draw(data, options);
}
</script>
<div id="chart_div"></div>
';
這裏的問題是,即使我得到的正確的值JSON變量,而加載相同的谷歌圖表得到低於錯誤,因此圖表沒有得到顯示。
"Uncaught Error: Invalid type, int, for column "col2".
at gvjs_R.gvjs_.Sda
請幫助理解這個問題。
非常感謝。這工作很好.. –