Highcharts动态显示多条实时曲线,怎么初始化数据

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Highcharts动态显示多条实时曲线,怎么初始化数据相关的知识,希望对你有一定的参考价值。

参考技术A $(function ()
$(document).ready(function ()
Highcharts.setOptions(
global:
useUTC: false

);
var chart;
$('#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];
var series1 = this.series[1];
setInterval(function ()
var x = (new Date()).getTime(), // current time
y = Math.random();
y2 = Math.random();
series.addPoint([x, y], true, true);
series1.addPoint([x, y2], true, true);
, 1000);


,
title:
text: 'demo(样例)'
,
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: (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;
)()
,
name: 'Random data1',
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;
)()
]
);
);
);本回答被提问者和网友采纳

Html实时显示数据曲线(基于Highcharts )

直接上源码,这个源码也是从其他地方下载的,验证可用。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE>实时更新数据的jQuery图表插件DEMO演示</TITLE>

<!-- <script type="text/javascript" src="js/jquery.js"></script> -->
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<!-- <script type="text/javascript" src="js/highcharts.js"></script> -->
<script type="text/javascript" src="http://code.highcharts.com/highcharts.js"></script>

<script type="text/javascript">
$(function () {
$(document).ready(function() {
	Highcharts.setOptions({
		global: {
			useUTC: false
		}
	});

	var chart;
	$('#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(), // current time
							y = Math.random();
						series.addPoint([x, y], true, true);
					}, 10000);
				}
			}
		},
		title: {
			text: 'CPU动态走势图--1秒2'
		},
		xAxis: {
			type: 'datetime',
			tickPixelInterval: 100
		},
		yAxis: {
			title: {
				text: 'CPU动态走势图--1秒1'
			},
			plotLines: [{
				value: 0,
				width: 1,
				color: '#808080'
			}]
		},
		tooltip: {
			formatter: function() {
					return 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: (function() {
				// generate an array of random data
				var data = [],
					time = (new Date()).getTime(),
					i;
				// 数据在这里初始化
				for (i = -9; i <= 0; i++) {
					data.push({
						x: time + i * 10000,
						// y: 5
						y: Math.random()
					});
				}
				return data;
			})()
		}]
	});
});

});
</script>
</HEAD>

<BODY>
<div id="status" name="status">状态信息</div>
<div id="container" style="width:700px;height:400px;margin:0 auto;"></div>
<div style="text-align:center;clear:both;">
</div>
</BODY>
</HTML>

效果:

 有个地方可以学习Highcharts。比较详细,应用够用了。

https://www.runoob.com/highcharts/highcharts-tutorial.html

以上是关于Highcharts动态显示多条实时曲线,怎么初始化数据的主要内容,如果未能解决你的问题,请参考以下文章

highcharts柱状图的数据怎么显示到中间去了

Highcharts,停止动态样条曲线图的渲染

用highcharts做了一个曲线图,每个点的颜色不同,想添加一个图例来显示每个颜色代表的含义,请问怎么做呢

C# ZedGraph实时多条曲线数据更新实例

在.NET MVC 中使用Highcharts+Ajax+Json生成动态曲线图,柱状图,饼图

关于Highcharts数据量超过1000时无法显示问题