舍入导致highcharts jquery脚本

我知道这有点……但反正会问。 我正在使用highcharts jquery脚本(http://www.highcharts.com/)来生成饼图。 我试图在饼图中舍入数字结果,但找不到任何文档。 我被卡住了!

我的数据看起来像这样:

data: [ ['Equity', 3], ['Cash', 6] ] 

饼图输出:33.333333333333和66.666666666666

我宁愿分别上下调整结果,所以它读取并显示33和64.是否有人知道如何在highcharts中设置它?

在配置对象的工具提示选项中,在formatter函数中使用Math.round()。

  tooltip: { formatter: function() { return ''+ this.point.name +': '+ Math.round(this.percentage) +' %'; } }, 
 tooltip: { valueDecimals: 2 }, 

您可以使用Highcharts API中提供的numberFormatfunction(请参阅http://www.highcharts.com/ref/#highcharts-object )。

引自API doc:

numberFormat (Number number,[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:Number要格式化的原始数字。
  • decimals:Number所需的小数位数。
  • decimalPoint:String小数点。 默认为“。” 或者在options.lang.decimalPoint中全局指定的字符串。
  • thousandsSep:String千位分隔符。 默认为“,”或者在options.lang.thousandsSep中全局指定的字符串。

返回

带有输入数字格式的字符串。

您可以将yDecimals设置为2而不是使用formatter

 tooltip: { yDecimals: 2 } 

yDecimalsNumber
How many decimals to show in each series' y value. This is overridable in each series' tooltip options object. The default is to preserve all decimals.

 tooltip: { formatter: function() { return ''+ this.point.name +': '+ Math.round(this.percentage*100)/100 +' %'; } }, 

尝试

 percentageDecimals: 0 

在你的工具提示中