Php实时谷歌图表
我正在用mysql制作一个图表,我想实时运行或者每10秒更新一次 我的数据库是关于天气的,通过arduino天气盾收集数据。。。。 我可以在单击该页面时显示图表,但我想每5秒更新数据库中记录的数据这是我的代码,希望有人能提供帮助:Php实时谷歌图表,php,mysql,Php,Mysql,我正在用mysql制作一个图表,我想实时运行或者每10秒更新一次 我的数据库是关于天气的,通过arduino天气盾收集数据。。。。 我可以在单击该页面时显示图表,但我想每5秒更新数据库中记录的数据这是我的代码,希望有人能提供帮助: <?php function tempf($input,$name){ global $conn; echo ' <script type="text/javascript" src="https://www.google.com/jsapi">&
<?php
function tempf($input,$name){
global $conn;
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 = google.visualization.arrayToDataTable([
["Year", "'.$name.'"],';
$resultValue = mysqli_query($conn, "SELECT * FROM daily ORDER BY timeStamp DESC LIMIT 200 ");
if(mysqli_num_rows($resultValue)>0){
while($rowValue = mysqli_fetch_array($resultValue)){
echo '["'.$rowValue['timeStamp'].'", '.$rowValue[''.$input.''].'],';
}
}
echo ']);
var options = {
title: "Graph"
};
var chart = new google.visualization.LineChart(document.getElementById("chart_div"));
chart.draw(data, options);
}
</script>
<div id="chart_div" style="width: 900px; height: 500px; margin-left:4.5cm; "></div>';
}
?>
使用Javascript执行此操作非常简单,无需刷新页面,替换折线图。通过以下方式绘制(数据、选项):
如果您想了解更多关于javascript、jquery和php的web开发教程,请查看:使用javascript每5分钟刷新一次页面seconds@kimbarcelona我可以做到,但我有一个实时背景,图表使用延迟来显示,所以我不能使用它
function update(){
timerId = setTimeout(function () {
chart.draw(data, options);
}, 5000);
}
update();