highcharts实现实时动态的折线面积图


首先去highcharts官网下载highcharts.js


1,HTML

<!DOCTYPE>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<title>Document</title>
		<link href="../css/sheet.css" type="text/css" rel="stylesheet" />
		<script src="../js/jquery-1.8.1.min.js"></script>
		<script src="../js/controlPanel/highcharts.js"></script>
		<script src="../js/controlPanel/sheet.js"></script>
		<style>
			#container {
				background: transparent !important;
				fill: transparent !important;
			}
			
			. highcharts-background {
				fill: transparent !important;
			}
			
			#highcharts-0 rect {
				fill: transparent !important;
			}
			
			
		</style>
		<script src="./js/jquery-1.11.1.min.js"></script>
	</head>

	<body>
		<div id="content">
			<div class="line">
				<div class="content-canvas">
					<div id="container" style="width: 100%; height:100%; "></div>
				</div>
			</div>
			
		</div>
		
	</body>

</html>
2,js

$(document).ready(function() {
				Highcharts.setOptions({
					global: {
						useUTC: false
					},
					colors: "#F8D366,#A4DB81".split(","),
					symbols: ["circle", "triangle"]
				});
				var options = {
					chart: {
						renderTo: 'container',
						type: 'area',
						marginRight: 10,
						events: {
							load: function() {
								// set up the updating of the chart each second
								// var series = this.series[0];
								$.each(this.series, function(idx, series) {
									setInterval(function() {
										var x = (new Date()).getTime(), // current time
											y = Math.random();
										series.addPoint([x, y], true, true);
									}, 1000);
								});
							}
						}
					},
					title: {
						text: ''
					},
					subtitle: {
						text: "Intel(R) Core (TM) i5-3230M CPU@2.60Ghz",
						align:'right',
						color:'#666'
					},
					credits: {
						enabled: false
					},
					exporting: { //Highcharts 图表导出功能模块。
						enabled: false
					},
					xAxis: {
						type: 'datetime',
						tickPixelInterval: 80,
						 gridLineWidth: 0,//Y
						// tickwidth:0,
					},
					yAxis: {
						title: {
							text: 'Kbps'
						},
						 gridLineWidth: 0,//隐藏点横线
						startOnTick: true, //为true时,设置min才有效
						min: 0,
						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/>' + '<span style="color:#08c">' +
								Highcharts.numberFormat(this.y, 2) + ' Kbps' + '</span>';
						}
					},
					legend: {
						enabled: true
					},
					exporting: {
						enabled: false
					},
					//禁止图例点击
					plotOptions: {
						series: {
							events: {
								legendItemClick: function(e) {
									return false; // 直接 return false 即可禁用图例点击事件
								}
							},
							marker:{
								enabled:false
							}
						}
					},
					series: [{
						name: ' ',
						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;
						})()
					}]
				};
				chart = new Highcharts.Chart(options);
			});


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值