如何从 setinterval 中定义的函数中访问系列数据。当我尝试访问任何值,甚至数组长度时,它会显示未定义。
events: {
load: function() {
// set up the updating of the chart each second
var series0 = this.series[0];
var series1 = this.series[1];
var series2 = this.series[2];
var series3 = this.series[3];
setInterval(function() {
var y = $.ajax({url: "/index.php/control/fetch/<?php echo $uid; ?>",async: false}).responseText;
y = y.split(" ");
var x = parseInt(y[0]);
//alert("x = " + series0[0]);
//alert("len is " + parseInt(series0.length));
series0.addPoint([x, parseFloat(y[1])], true, true);
series1.addPoint([x, parseFloat(y[2])], true, true);
series2.addPoint([x, parseFloat(y[3])], true, true);
series3.addPoint([x, parseFloat(y[4])], true, true);
}, 5000);
}
}
谢谢