我制作了一个Google折线图,其中应显示从MySQL数据库获取的度量。它显示了它,但是问题是我需要重新加载页面才能出现新的度量。如何使图表每10秒钟更新一次新数据(将数据添加到数据库的时间间隔)。此外,我还需要帮助添加多条线并添加一个十字线,该十字线会在鼠标位于图表区域时显示,而不仅是在线本身。 这是我的代码: Linechart.php:
<?php
$curyear = date('Y');
$con = mysqli_connect('localhost','u644759843_miki','plantaze2020!','u644759843_plantazeDB');
?>
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
// Create the data table.
var data = google.visualization.arrayToDataTable([
['Date', 'Product Purity',],
<?php
$query = "SELECT `FlowRate`, `ProductPurity`, `TimesStamp` FROM `Precizno ProductPurity` WHERE `TimesStamp` >= ( CURDATE() - INTERVAL 3 DAY ) ORDER BY `TimesStamp` DESC";
$exec = mysqli_query($con,$query);
while($row = mysqli_fetch_array($exec)){
date("H:i:s",strtotime($time));
echo "['".date("H:i", strtotime($row['TimesStamp']))."', ".$row['ProductPurity'].",],";
}
?>
]);
// Set chart options
var options = {'title':'Nitrogen Generator',
'width':1200,
'height':300,
'crosshair': { trigger: 'both' }
// isStacked: true
};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<!--Divs that will hold the charts-->
<div id="chart_div"></div>
</body>
</html>