我知道这有点离谱...但不管怎样我还是要问。我正在使用highcharts jquery脚本(http://www.highcharts.com/)来生成一个饼图。我正在尝试对饼图中的数字结果进行四舍五入,但找不到任何文档来这样做。我卡住了!
我的数据看起来像这样:
data: [
['Equity', 3],
['Cash', 6]
]饼图输出: 33.333333333333和66.666666666666
我宁愿将结果分别向上和向下四舍五入,这样它就会读取并显示33和64。有没有人知道如何在highcharts中设置它?
发布于 2012-02-01 12:28:36
在configuration对象的工具提示选项中,在格式化程序函数中使用Math.round()。
tooltip: {
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ Math.round(this.percentage) +' %';
}
},发布于 2013-08-01 05:13:46
tooltip: {
valueDecimals: 2
},发布于 2012-02-01 16:50:01
Highcharts API中有一个您可以使用的numberFormat函数(请参阅http://www.highcharts.com/ref/#highcharts-object)。
引用自API文档:
数字小数(numberFormat,number decimals,String decimalPoint,String thousandsSep):String
使用分组的千位数、固定小数位数和可选小数点对JavaScript数字进行格式化。它是PHP函数的一个同名端口。有关这些参数的完整说明,请参阅PHP number_format。
tooltip: {
formatter: function() {
return ''+ this.series.name +''+
this.x +': '+ Highcharts.numberFormat(this.y, 0, ',') +' millions';
}
}, ...参数
Number数字:将原始数字转换为format.
中全局指定的字符串
返回
带有输入数字格式的字符串。
https://stackoverflow.com/questions/9085644
复制相似问题