您的位置:首页 > 其它

实时动态更新曲线图,x轴时间s随数据的变化而变化

2016-10-25 22:23 746 查看
$(function () {
$(document).ready(function () {
Highcharts.setOptions({
global: {
useUTC: false
}
});
$('#container').highcharts({
chart: {
type: 'spline',
animation: Highcharts.svg, // don't animate in old IE
marginRight: 10,
events: {
load: function () {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function () {
var x = (new Date()).getTime().getSecond, // current time
y = Math.random();
series.addPoint([x, y], true);
}, 1000);
}
}
},
title: {
text: 'Live random data'
},
xAxis: {
tickInterval:(new Date()).getTime().getSecond
},
yAxis: {
title: {
text: 'Value'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function () {
return '<b>' + this.series.name + '</b><br/>' +
this.x + '<br/>' +
Highcharts.numberFormat(this.y, 2);
},
crosshairs:[true,true]//显示十指线
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
series: [{
name: 'Random data',
data: (function () {
// generate an array of random data
var data = [],
time = (new Date()).getTime().getSecond,
i;
for (i = -19; i <= 0; i += 1) {
data.push({
x: time ,
y: Math.random()
});
}
return data;
}())
}]
});
});
});

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: