我利用jquery 的highcharts图表实现实时曲线,现在有一个问题不知如何解决,
http://www.highcharts.com/demo/dynamic-update/grid 参靠地址 代码如下:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WellScan.aspx.cs" Inherits="sinoperm.WellPOC.UI.UI.WellScan" %><!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 runat="server">
<title></title>
<script type="text/javascript" src="../Scripts/jquery/jquery-1.4.1.js"></script>
<script type="text/javascript" src="../Scripts/highcharts.js"></script>
<script type='text/javascript'>
$(function () {
$(document).ready(function () { Highcharts.setOptions({ global: { useUTC: false } }); var chart; chart = new Highcharts.Chart({ chart: { renderTo: 'container', type: 'spline', 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); }, 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: (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; })() }] }); });
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="container" style="height: 400px">
</div>
</form>
</body>
</html>
事件中产生的随机点没有任何问题,现在我要把这个Y轴的点通过后台json中获取数据进行改变,我通过ajax对这个代码进行了更改,数据获取到后,页面的曲线应该是随着时间的移动向左消失的,但加了ajax后不消失而是不段在页面中累加变挤,不知为什么,是不是有什么属性需要设置还是我的程序写的有问题,还是只能在event事件进行操作呢。谢谢
http://www.highcharts.com/demo/dynamic-update/grid 参靠地址 代码如下:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WellScan.aspx.cs" Inherits="sinoperm.WellPOC.UI.UI.WellScan" %><!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 runat="server">
<title></title>
<script type="text/javascript" src="../Scripts/jquery/jquery-1.4.1.js"></script>
<script type="text/javascript" src="../Scripts/highcharts.js"></script>
<script type='text/javascript'>
$(function () {
$(document).ready(function () { Highcharts.setOptions({ global: { useUTC: false } }); var chart; chart = new Highcharts.Chart({ chart: { renderTo: 'container', type: 'spline', 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); }, 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: (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; })() }] }); });
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="container" style="height: 400px">
</div>
</form>
</body>
</html>
事件中产生的随机点没有任何问题,现在我要把这个Y轴的点通过后台json中获取数据进行改变,我通过ajax对这个代码进行了更改,数据获取到后,页面的曲线应该是随着时间的移动向左消失的,但加了ajax后不消失而是不段在页面中累加变挤,不知为什么,是不是有什么属性需要设置还是我的程序写的有问题,还是只能在event事件进行操作呢。谢谢
我参考这个做的,他这个也是不移动的x轴的时间是随机的,不是取出来的