我对 HighCharts、HighStock 和实时数据/实时图表有一个大问题。
请检查 :
http://jsfiddle.net/5RutC/160/
并尝试删除第一个系列(随机数据)。图表将停止更新。如果您重新选择该系列的第一个,它将继续更新所有值。
是否有可能以某种方式克服这个问题,或者是 HighCharts/HighStock 的错误?
谢谢
HTML 代码:
<script src="http://code.highcharts.com/stock/highstock.js"></script>
<script src="http://code.highcharts.com/stock/modules/exporting.js"></script>
<div id="container" style="height: 500px; min-width: 500px"></div>
Javascript代码:
$(function() {
Highcharts.setOptions({
global : {
useUTC : false
}
});
// Create the chart
window.chart = new Highcharts.StockChart({
chart : {
renderTo : 'container',
events : {
load : function() {
// set up the updating of the chart each second
var series = this.series[0];
var series1 = this.series[1];
var chart = this;
setInterval(function() {
var x = (new Date()).getTime(), // current time
y = Math.round(Math.random() * 100);
y1 = Math.round(Math.random() * 100);
series.addPoint([x, y], false, true);
series1.addPoint([x, y1], false, true);
chart.redraw();
}, 1000);
}
}
},
rangeSelector: {
buttons: [{
count: 1,
type: 'minute',
text: '1M'
}, {
count: 5,
type: 'minute',
text: '5M'
}, {
type: 'all',
text: 'All'
}],
inputEnabled: false,
selected: 0
},
title : {
text : 'Live random data'
},
legend: {
align: 'right',
layout: 'vertical',
verticalAlign: 'top',
y: 45,
enabled: 'true'
},
exporting: {
enabled: false
},
series : [{
name : 'Random data',
data : (function() {
// generate an array of random data
var data = [], time = (new Date()).getTime(), i;
for( i = -999; i <= 0; i++) {
data.push([
time + i * 1000,
Math.round(Math.random() * 100)
]);
}
return data;
})()
},{
name : 'Random data2',
data : (function() {
// generate an array of random data
var data = [], time = (new Date()).getTime(), i;
for( i = -999; i <= 0; i++) {
data.push([
time + i * 1000,
Math.round(Math.random() * 100)
]);
}
return data;
})()
}]
});
});
</p>