如何在固定时间间隔(例如 10 秒)后更新 jqplot 条形图?我编写了以下代码,其中 y 轴数据是随机生成的,但在固定时间间隔后不会更新。
<?php
$x = array();
$y = array();
for($i=0;$i<50; $i++)
{
$x[] = $i;
$y[] = rand(10, 200);
}
$x_data = json_encode($x);
$y_data = json_encode($y);
Yii::app()->clientScript->registerScript('chart_big',"
$(document).ready(function(){
$.jqplot.config.enablePlugins = true;
var s2 = $y_data;
var ticks = $x_data;
plot5 = $.jqplot('chart_big', [s2], {
// Only animate if we're not using excanvas (not in IE 7 or IE 8)..
animate: !$.jqplot.use_excanvas,
seriesDefaults:{
renderer:$.jqplot.BarRenderer,
pointLabels: { show: true }
},
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
ticks: ticks
}
},
highlighter: { show: false }
});
$('#chart1').bind('jqplotDataClick',
function (ev, seriesIndex, pointIndex, data) {
$('#info1').html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data);
}
);
$('a[href=\"#yw1_tab_4\"]').on('shown', function(g) {
if (plot5._drawCount === 0) {
plot5.replot();
}
});
setInterval(function () {
s2 = $y_data;
ticks = $x_data;
plot5.series[0].data = s2;
plot5.replot();
}, 10000);
});
");
?>