im目前正在使用MorrisJS开发PHP网页图,并每5秒钟刷新一次数据。我无法在页面上生成静态图。不幸的是,我的图形无法在不刷新页面的情况下更新图形。是否有任何缺少的代码导致此AJAX无法正常工作? 我仍然使用此MorrisJS和AJAX还是新手。 对不起,我的英语不好。
<h4>Graph</h4>
<link rel='stylesheet' href='//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css'>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>
<div id="chart"></div>
<script>
var chart = Morris.Line({
element:'chart',
data:[{ date:'2019-05-14 10:31:54.577', 2001:4037}, { date:'2019-05-14 10:31:34.580', 2001:4040}, { date:'2019-05-14 10:31:14.577', 2001:4051}],
xkey: 'date',
ykeys: [2001],
labels:[2001],
hideHover: 'auto',
ymin: 4037,
ymax: 4061,
redraw: true
});
var updateChart = function() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var part = JSON.parse(this.responseText);
chart.data=part[0];
}
};
xmlhttp.open("POST", "DATA/updateData.php?sec=BLOCK1&pot=2001", true);
xmlhttp.send();
}
setInterval(function(){updateChart()},5000);
</script>