这是带有随机数据http://jsfiddle.net/Fw4PZ/的示例图表
$(function () {
$(document).ready(function() {
Highcharts.setOptions({
global: {
useUTC: false
}
});
var chart;
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'area',
marginRight: 10,
events: {
load: function() {
// set up the updating of the chart each second
var series = this.series[1];
setInterval(function() {
var x = (new Date()).getTime(), // current time
y = Math.random();
series.addPoint([x, y], true);
}, 1000);
}
}
},
title: {
text: 'Live random data'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150
},
yAxis: {
title: {
text: 'Value'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'<br/>'+
Highcharts.numberFormat(this.y, 2);
}
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
series: [{
name: 'Random data',
data: []
},{
name: 'Random data',
type: 'spline',
data: []
}]
});
});
});如何更新每一个系列,而不仅仅是一个?
load: function() {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function() {
var x = (new Date()).getTime(), // current time
y = Math.random();
series.addPoint([x, y], true);
}, 1000);
// set up the updating of the chart each second
var series = this.series[1];
setInterval(function() {
var x = (new Date()).getTime(), // current time
y = Math.random();
series.addPoint([x, y], true);
}, 1000);
}不管用..。
第二件事..。如何使用ajax更新这些系列?(我需要有2个区域和4个样条)
更新,所以我改变了这个
events: {
load: function() {
// set up the updating of the chart each second
var series = this.series;
setInterval(function() {
var x = (new Date()).getTime(), // current time
y = Math.random();
series[0].addPoint([x, y], false);
series[1].addPoint([x, y], false);
series[2].addPoint([x, y], false);
series[3].addPoint([x, y], false);
series[4].addPoint([x, y], false);
series[5].addPoint([x, y], true);
}, 5000);
}
}但是它使我的浏览器崩溃了:\ http://jsfiddle.net/2tmRB/1/ (注意那个链接!)我做错什么了?
发布于 2013-05-21 11:46:12
示例:
var series = this.series;
setInterval(function() {
var x = (new Date()).getTime(), // current time
y = Math.random(),
y1 = Math.random();
series[0].addPoint([x, y], false);
series[1].addPoint([x, y1], true);
}, 1000);实例:http://jsfiddle.net/Fw4PZ/1/
关于AJAX --只是在setInterval中调用一些getJSON()或类似的东西,并使用addPoint()将来自该响应的值添加到图表中(如上面的示例所示)。
https://stackoverflow.com/questions/16668051
复制相似问题