HighCharts常见使用问题总结(个人笔记)

来源:互联网 发布:mac project软件 编辑:程序博客网 时间:2024/05/22 22:59

1、隐藏掉HightChart自带的官网链接

添加以下代码:credits: {    enabled: false //去掉官网链接}此节点是官方标准的控制版权信息的节点,属性包括:enabled(是否显示,默认true)、href(链接地址,默认highchart官网)、position(控制位置)、style(样式)、text(文字内容)

2、3D饼图添加legend效果。

(1)在plotOptions/pie节点下添加showInLegend属性(在其他地方添加不好使)(2)在主节点下添加legend设置$('#container').highcharts({    ...    plotOptions: {        pie: {              innerSize: 100,              depth: 45,              showInLegend:true            }        },    legend: {        layout: 'vertical',        ...        labelFormatter: function () { //百分比格式化            return this.name + '('+this.percentage+'%)';        }    }    ...})

官网上API是这样说的:showInLegend: Boolean
Whether to display this particular series or series type in the legend. Since 2.1, pies are not shown in the legend by default.
意思是说是否要显示这个特殊的数据序列或者数据图例。从2.1版本开始,饼图默认不显示此图例

3、HightCharts数字格式化方法(内容摘抄自HightCharts中文社区)。

(1)函数构造及参数
Highcharts.numberFormat (Number number, [Number decimals], [String decimalPoint], [String thousandsSep])
–参数列表–
number 需要格式化的数字
decimals 小数保留位数,最后一位是四舍五入,默认为 0(可选参数)
decimalPoint 小数点符,默认是“.”(可选参数)
thousandsSep 千位符,默认是“,” (可选参数)
返回值类型:String

(2)示例
对于数字 12223.8723
Highcharts.numberFormat(12223.87)= 12,224(默认精度是0)
Highcharts.numberFormat(12223.87, 2)= 12223.87(保留两位小数)
Highcharts.numberFormat(12223.87, 2, “,”, ” “)= 12223,87(小数点用“,”,千分符用“ ”)
Highcharts.numberFormat(12223.87, 2, “.”, “”)= 12223.87(不显示千分符)

(3)具体应用
应用前:
formatter: function() {
return this.point.name + this.percentage + ‘%’;
}
这里写图片描述
应用后:
formatter: function() {
return this.point.name + Highcharts.numberFormat(this.percentage,2) + ‘%’;
}
这里写图片描述

原创粉丝点击