Javascript Highcharts 图表值的数字格式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/11881032/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Number Formatting at Highcharts Chart Values?
提问by kamaci
I give that values to Highcharts pie chart:
我将这些值赋予 Highcharts 饼图:
  series:[
        {
            type:'pie',
            name:'Ratio',
            data:[
                ['A', 42.6],
                {
                    name:'B',
                    y:14.2,
                    sliced:true,
                    selected:true
                }
            ]
        }
    ]
However it shows it like that at pie chart:
但是它在饼图中显示如下:
A -> 75.00000000000001 %
B-> 25 %
You can format tooltips at Highcharts how about chart values?
您可以在 Highcharts 格式化工具提示,图表值如何?


回答by Dennis
plotOptions.pie.dataLabels.formatteris a function that will let you format the label.  In this case I returned this.percentage.toFixed(2)which will trim your number at 2 decimal places. Demo at this jsFiddle
plotOptions.pie.dataLabels.formatter是一个可以让你格式化标签的函数。在这种情况下,我返回this.percentage.toFixed(2)了它将在小数点后 2 位修剪您的数字。在这个 jsFiddle 上演示
plotOptions: {
    pie: {
        dataLabels: {
            formatter: function() {
                return '<b>' + this.point.name + '</b>: ' + this.percentage.toFixed(2) + ' %';
            }
        }
    }
},
回答by pdpMathi
We do have tooltip formatter options to display the value as number instead of percentage
我们确实有工具提示格式化程序选项可以将值显示为数字而不是百分比
http://api.highcharts.com/highstock#tooltip.formatter
http://api.highcharts.com/highstock#tooltip.formatter
tooltip: {
   formatter: function() {
      return '<b>'+ this.point.name +'</b>: '+ this.point.y ;
   }
},
this.point.y will do the trick (now you have this.percentage in that place)
this.point.y 会解决这个问题(现在你在那个地方有 this.percentage)
回答by Stevie Qiao
You can just format it like this below.
你可以像下面这样格式化它。
    tooltip: {
    pointFormat: "Value: {point.y:.2f}"
}
回答by Adams.H
tooltip: {
   pointFormat: "Value: {point.y:.2f}"
}
this is not for formating the values .
这不是为了格式化值。
var data = [{
     name: 'Population',
     data: [],
     dataLabels: {
         enabled: true,
         rotation: -90,
         color: '#FFFFFF',
         align: 'right',
         x: 4,
         y: 10,
         style: {
             fontSize: '13px',
             fontFamily: 'Verdana, sans-serif',
             textShadow: '0 0 3px black'
         }, formatter: function() {
             return  Highcharts.numberFormat(this.y, 2, '.');
         }
     }
}];
the formart of the values can be change in the dataLables in the data .
值的格式可以在 data 中的 dataLables 中更改。
回答by Oduwole Oluwasegun
  tooltip: {
    pointFormat: "Percentage: {point.percentage:.2f}"
}
This will give you the percentage value
这会给你百分比值

