使用HighCharts描绘多个Y轴的动态曲线。
2014-06-11 17:08
337 查看
调试了一整天,终于显示出来了。
详细例子参照官网的demo:http://www.hcharts.cn/demo/index.php
在这只贴出关键部分的JS代码
1. chart (就是在events的load里写一个实时获取的方法。通过json调用去后台拉新数据加到series里)
2. series (就是图的折线数据,可以只提供Y值) 这里提供折线的初始数据,同样可以写个方法去后台抓初始数据。
3. tooltip 把这个也拿出来讲,是因为当多个折线的单位不一样时,可以通过判断当前点的series的命名来区分,即第2点定义的name。
详细例子参照官网的demo:http://www.hcharts.cn/demo/index.php
在这只贴出关键部分的JS代码
1. chart (就是在events的load里写一个实时获取的方法。通过json调用去后台拉新数据加到series里)
chart: { renderTo: 'chart_spline', //图表放置的容器,DIV defaultSeriesType: 'spline', //图表类型为曲线图 events: { load: function () { //获取series对象 var a= this.series[0]; var b= this.series[1]; var c= this.series[2]; setInterval(function () { //add new item from json request to a $.getJSON( "/xxxxxxxxxxxxxxxx/", function (data) { $.each(data, function (k, v) { var x = (new Date()).setSeconds(0), // 当前时间 y = v.value; //Math.random() * 100; a.addPoint([x, y], true, true); }); }); //add new item from json request to b $.getJSON( "/xxxxxxxxxxxxxxxx/", function (data) { $.each(data, function (k, v) { var x = (new Date()).setSeconds(0), // 当前时间 y = v.value; //Math.random() * 100; b.addPoint([x, y], true, true); }); }); //add new item from json request to c $.getJSON( "/xxxxxxxxxxxxxxxx/", function (data) { $.each(data, function (k, v) { var x = (new Date()).setSeconds(0), // 当前时间 y = v.value; //Math.random() * 100; c.addPoint([x, y], true, true); }); }); }, //每隔60秒钟,图表更新一次 60000); } } },
2. series (就是图的折线数据,可以只提供Y值) 这里提供折线的初始数据,同样可以写个方法去后台抓初始数据。
series: [{ name: 'Tokyo', data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6] }, { name: 'New York', data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5] }, { name: 'Berlin', data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0] }]
3. tooltip 把这个也拿出来讲,是因为当多个折线的单位不一样时,可以通过判断当前点的series的命名来区分,即第2点定义的name。
tooltip: {//当鼠标悬置数据点时的提示框 formatter: function () { //格式化提示信息 var info = '<b>' + Highcharts.dateFormat('%H:%M:%S', this.x) + '</b>'; if (this.series.name == 'Tokyo') { info += '<br/>' + this.series.name + ': ' + this.y + '%';//单位 }; if (this.series.name == 'New York') { info += '<br/>' + this.series.name + ': ' + this.y + '℃';//单位 }; if (this.series.name == 'Berlin') { info += '<br/>' + this.series.name + ': ' + this.y + '$';//单位 }; return info; }, },
相关文章推荐
- Highcharts动态曲线图(使用jna监视cpu使用率)
- android下使用RChart画曲线图动态刷新
- ASP.NET中动态获取数据使用Highcharts图表控件
- 使用Highcharts实现柱状图、饼状图、曲线图三图合一
- Flex 动态创建多个曲线图/柱形图 ColumnSeries
- ASP.NET中动态获取数据使用Highcharts图表控件【Copy By Internet】
- 使用Jfreechart 在applet中画动态曲线图
- 使用highcharts实现实时监控曲线图
- highcharts 高级应用—动态曲线的实现
- highcharts 高级应用—动态曲线的实现
- 使用 amcharts 和 highcharts 绘制多曲线时间趋势图的通用方法
- Flex动态创建多个曲线图+柱形图
- Flex动态创建多个曲线图+柱形图
- Flex动态创建多个曲线图+柱形图
- 泛型使用,及 动态显示多个类的属性名与值的 例子
- Flex动态创建多个曲线图+柱形图
- 使用Highcharts生成折线图与曲线图
- 使用Highcharts生成折线图与曲线图
- 使用 amcharts 和 highcharts 绘制多曲线时间趋势图的通用方法