Highcharts 双轴车速表
下图是一个 Highcharts 双轴车速表
配置
-
配置属性 chart.type 为 'gauge' 即可将图表显示为 双轴车速表
var chart = { type: 'guage' };
-
配置属性 pane
属性 pane 只适用在极坐标图和角度测量仪
pane 属性可配置对象持有组合 x 轴和 y 周的常规选项
每个 x 轴和 y 轴都可以通过索引关联到窗格中
pane.startAngle 是 x 轴或测量轴的开始度数,以度数的方式给出,0 是北
pane.endAngle 是 x 轴极坐标或角度轴的最终度数,以度数的方式给出,0 是北
var pane = { startAngle: -150, endAngle: 150 };
范例
下面的代码列出了 Highcharts 双轴车速表 的基本配置
<!doctype html> <meta charset="utf-8" /> <title>Highcharts 基础教程 | 简单教程(www.twle.cn)</title> <script src="https://cdn.hcharts.cn/highcharts/highcharts.js"></script> <script src="https://cdn.hcharts.cn/highcharts/highcharts-more.js"></script> <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script> <div id="container" style="width: 550px; height: 400px; margin: 0 auto"></div> <script> var chart = { type: 'gauge', plotBackgroundColor: null, plotBackgroundImage: null, plotBorderWidth: 0, plotShadow: false }; var credits = { enabled: false }; var title = { text: '双轴车速表' }; var pane = { startAngle: -150, endAngle: 150 }; // the value axis var yAxis = [{ min: 0, max: 200, lineColor: '#339', tickColor: '#339', minorTickColor: '#339', offset: -25, lineWidth: 2, labels: { distance: -20, rotation: 'auto' }, tickLength: 5, minorTickLength: 5, endOnTick: false }, { min: 0, max: 124, tickPosition: 'outside', lineColor: '#933', lineWidth: 2, minorTickPosition: 'outside', tickColor: '#933', minorTickColor: '#933', tickLength: 5, minorTickLength: 5, labels: { distance: 12, rotation: 'auto' }, offset: -20, endOnTick: false }]; var series= [{ name: 'Speed', data: [80], dataLabels: { formatter: function () { var kmh = this.y, mph = Math.round(kmh * 0.621); return '<span style="color:#339">' + kmh + ' km/h</span><br/>' + '<span style="color:#933">' + mph + ' mph</span>'; }, backgroundColor: { linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, stops: [ [0, '#DDD'], [1, '#FFF'] ] } }, tooltip: { valueSuffix: ' km/h' } }]; var chart1; // Add some life var chartFunction = function (chart) { setInterval(function () { var point = chart1.series[0].points[0], newVal, inc = Math.round((Math.random() - 0.5) * 20); newVal = point.y + inc; if (newVal < 0 || newVal > 200) { newVal = point.y - inc; } point.update(newVal); }, 3000); }; var options = {}; options.chart = chart; options.title = title; options.pane = pane; options.yAxis = yAxis; options.series = series; var chart1 = Highcharts.chart('container',options); </script>
以上范例输出如下