0
試圖讓Google圖表通過php從本地mysql數據庫加載數據。頁面顯示空白。基於此example code。任何想法如何解決?Google Charts mysql PHP
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi?autoload={
'modules':[{
'name':'visualization',
'version':'1',
'packages':['corechart']
}]
}"></script>
<script type="text/javascript">
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Time', 'Temperature'],
<?php
$con = mysqli_connect("localhost", "root", "pass", "TempDB2");
$query = "SELECT * FROM TempMeas";
$result = mysqli_query($con, $query);
mysqli_close($con);
while ($row = mysqli_fetch_array($result))
{
$time = $row['MeasTime'];
$temp = $row['Temp'];
echo "['$time', $temp],";
}
?>
]);
var options = {
title: 'Company Performance',
curveType: 'function',
legend: { position: 'bottom' }
};
var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="curve_chart" style="width: 900px; height: 500px"></div>
</body>
</html>
我認爲在提取之前調用mysqli_close()可能會關閉mysqli_fetch_array需要的連接 – 321zeno
謝謝嘗試,但仍然是空白。還有其他建議嗎? – graceyj20
JavaScript部分運行良好,所以問題是PHP。我會看到什麼'var_dump($ con)'和'var_dump($ result')返回 – 321zeno