highcharts工具提示格式数亿亿美元 [英] highcharts tooltip format millions billions
问题描述
我想在高线图折线图上显示几个大数字.
I want to display couple of points on a highcharts line chart which are big numbers.
例如100,000,10,000,000,1,000,000,000
e.g. 100,000, 10,000,000, 1,000,000,000
当我显示这些数字时,y轴会自动将数字格式化为100 k,10 M,1,000 M等,但工具提示仍会显示实际的大数字.
When I display these, the y axis automatically formats the number into 100 k, 10 M, 1,000 M etc but the tooltip still shows the actual big number.
是否可以在工具提示中将1,000,000,000显示为1 B或1000M.
Is it possible to show 1,000,000,000 as 1 B or 1000 M in the tooltip itself.
示例- http://jsfiddle.net/ynCKW/1/
我正在尝试使用numberFormat函数,但我认为它不是正确的函数.
I am trying to play with the numberFormat function but I dont think its the right function.
Highcharts.numberFormat(this.y,0)
我是否必须编写一个自定义函数来在工具提示中进行这种格式化?
Do I have to write a custom function which would do this formatting in the tooltip?
推荐答案
您可以使用与Highcharts核心中实现的逻辑相同的逻辑:
You can use the same logic as implemented in Highcharts core:
tooltip: {
formatter: function () {
var ret = '',
multi,
axis = this.series.yAxis,
numericSymbols = ['k', 'M', 'G', 'T', 'P', 'E'],
i = numericSymbols.length;
while (i-- && ret === '') {
multi = Math.pow(1000, i + 1);
if (axis.tickInterval >= multi && numericSymbols[i] !== null) {
ret = Highcharts.numberFormat(this.y / multi, -1) + numericSymbols[i];
}
}
return ret;
}
},
和jsFiddle: http://jsfiddle.net/ynCKW/2/
And jsFiddle: http://jsfiddle.net/ynCKW/2/
Highcharts v6的
我们可以调用内置方法,该方法应该更易于维护: http://jsfiddle .net/BlackLabel/ynCKW/104/
We can call build-in method, which should be easier to maintain: http://jsfiddle.net/BlackLabel/ynCKW/104/
tooltip: {
valueSuffix: '',
formatter: function () {
var axis = this.series.yAxis;
return axis.defaultLabelFormatter.call({
axis: axis,
value: this.y
});
}
},
这篇关于highcharts工具提示格式数亿亿美元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!