我有传感器将数据发送到数据库并存储在那里,传感器的数据在网站上显示为图表但不起作用 伙计们,我想让这些代码工作,我怎么能? 附:数据库存储实时数据,图表也实时显示值
这个PHP代码从数据库中获取数据..这是new.php
<?php
require 'mysql0.php';
$query="SELECT * FROM `pulsesensor`";
if($query_run=mysql_query($query))
{
echo "query executed<br>";
while($query_execute=mysql_fetch_assoc($query_run))
{
echo $query_execute['value'].'<br>';
//echo $query_execute['date'].'<br>';
}
}
else
{
echo "query not exicuted";
}
?>
和html代码是图表代码是
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0
auto">
</div>
<script>
/**
* Request data from the server, add it to the graph and set a timeout
* to request again
*/
function requestData() {
$.ajax({
url: 'new.php',
success: function(point) {
var series = chart.series[0],
shift = series.data.length > 20; // shift if the series is
// longer than 20
// add the point
chart.series[0].addPoint(point, true, shift);
// call it again after one second
setTimeout(requestData, 1000);
},
cache: false
});
}
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
defaultSeriesType: 'spline',
events: {
load: requestData
}
},
title: {
text: 'Live Heartbeats data'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150,
maxZoom: 20 * 1000
},
yAxis: {
minPadding: 0.2,
maxPadding: 0.2,
title: {
text: 'Value',
margin: 80
}
},
series: [{
name: 'heartbeats data',
data: []
}]
});
});
</script>
结果就是
有什么不对?