Highcharts - 没有初始数据的Dyanmic图 [英] Highcharts - Dyanmic graph with no initial data
本文介绍了Highcharts - 没有初始数据的Dyanmic图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果您使用动态样条更新打开此JSFiddle,它会在每秒开始更新之前加载20个点的系列。
示例我不想显示任何初始数据,并让间隔在他们进入时添加点。
所以我改变了:
系列:[{
name:'Random data',
data:(function(){
//产生一个随机数据数组
var data = [],
time =(new Date())。getTime(),
i;
for(i = -19; i <= 0; i ++){
data.push({
x:time + i * 1000,
y:Math.random()
});
}
返回数据;
})()
}]
至
系列:[{
name:'Random data',
data:[]
}]
但它没有添加点。是否有我缺少的东西?
解决方案
更改您的载入功能,以便移动参数在您添加之前不适用您的20个值,请参阅 此jsfiddle
load:function(){
//设置每秒更新图表
var series = this.series [0 ],
maxSamples = 20,
count = 0;
setInterval(function(){
var x =(new Date())。getTime(),//当前时间
y = Math.random();
series.addPoint (
[x,y]
,true
,(++ count> = maxSamples)
);
},1000);
}
If you open this JSFiddle with the dynamic spline update it loads the series with 20 points before it starts updating every second.
I don't want to display any initial data and let the interval add the points as they come in.
So I change:
series: [{
name: 'Random data',
data: (function() {
// generate an array of random data
var data = [],
time = (new Date()).getTime(),
i;
for (i = -19; i <= 0; i++) {
data.push({
x: time + i * 1000,
y: Math.random()
});
}
return data;
})()
}]
to
series: [{
name: 'Random data',
data: []
}]
But it doesnt add the points. Is there something I am missing?
解决方案
Change your load function so that the shift parameter doesn't apply before you've added your 20 values, see this jsfiddle
load: function() {
// set up the updating of the chart each second
var series = this.series[0],
maxSamples = 20,
count = 0;
setInterval(function() {
var x = (new Date()).getTime(), // current time
y = Math.random();
series.addPoint(
[x,y]
, true
, (++count >= maxSamples)
);
}, 1000);
}
这篇关于Highcharts - 没有初始数据的Dyanmic图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文