0
我有項目溫度mesuare使用mySQL存儲數據的beaglebone。 我能夠顯示谷歌圖表形式MySQL使用PHP,但我不能實時更新它,任何人都可以幫助我,非常感謝。實時更新谷歌圖表,php,mySQL
<html>
<head>
<title>BeagleBone Temperature</title>
<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 = google.visualization.arrayToDataTable([
['Time', 'Temperature'],
<?php
$con = mysqli_connect("localhost", "hoangviet", "hoangviet", "test");
$query = "SELECT * FROM TempMeas"; // form table
$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: 'BeagleBone Measured Temperature',
vAxis: { title: "Degrees Celsius" }
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>
實時更新意味着您希望不更新就更新它? – sandeepsure
沒錯,你能幫助我嗎? –
你需要每30秒調用一次ajax,它將是同步的方式。 – sandeepsure