莫菲    

功能强大的图表插件highcharts的使用

6年前发布  · 916 次阅读
  highcharts 
功能强大的图表插件highcharts设置:
1. 允许图表放大功能:

在chart属性中添加 zoomType:'x', 或者 zoomType:'y', 或者 zoomType:'xy',

chart: {
    type: 'area',
    zoomType: 'xy',
},
2.设置鼠标停留点出显示的信息:
tooltip: {
    pointFormat: "CPU: {point.y:,.1f} %"
},
3.横坐标设为时间(传进去的横坐标的时间是时间戳格式):
xAxis: {
    type: 'datetime',
},
4.不显示图表右下角的 Highcharts.com 图样
credits: {
    enabled: false
},
5.去掉highchart图表右下角的网址标识:
credits: {
    enabled: false
},
6.设置横坐标的时间,并定义鼠标停留点的展示样式:

横坐标设置为时间模式:

xAxis: {
    type: 'datetime',
},

鼠标停留点展示设置:

tooltip: {
    dateTimeLabelFormats: {
        day: '%Y-%m-%d',
        minute: '%H:%M',
    },
    formatter: function () {
        return '<b>时间:</b>'+  Highcharts.dateFormat('%Y年%m月%d日 %H:%M', this.key)  + '<br/><b>' + this.series.name + ':</b> ' + this.point.y + '%';
    }
},
7.更改属性
var diskChart = $('#disk-chart').highcharts();
diskChart.series[0].update(
        {
            name:key,
            lineWidth:2,
            type:'spline',
            marker: {symbol: 'circle', radius: 0},
            data:value,
        }
        , false);
8.添加没有数据时的样式:
1.包含一个在目录 highcharts/modules/no-data-to-display.js 下的文件
2.设置汉字的没有数据样式:
Highcharts.setOptions({lang: {noData: "暂无数据"}});
9.移除所有数据:
while(diskChart.series.length > 0){
    diskChart.series[0].remove(true);
}
10.添加series 数据:
var diskChart = $('#disk-chart').highcharts();
diskChart.addSeries({
    name:key,
    lineWidth:2,
    type:'spline',
    marker: {symbol: 'circle', radius: 0},
    data:value,
});
11.图标样式超出边框的情况使用
$('#chart').highcharts().reflow();