Number Formatting at Highcharts Chart Values?

别等时光非礼了梦想. 提交于 2020-01-02 00:52:13

问题


I give that values to Highcharts pie chart:

  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?


回答1:


We do have tooltip formatter options to display the value as number instead of percentage

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)




回答2:


plotOptions.pie.dataLabels.formatter is 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: function() {
                return '<b>' + this.point.name + '</b>: ' + this.percentage.toFixed(2) + ' %';
            }
        }
    }
},



回答3:


You can just format it like this below.

    tooltip: {
    pointFormat: "Value: {point.y:.2f}"
}

documentation about Highcharts formatting




回答4:


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 .




回答5:


  tooltip: {
    pointFormat: "Percentage: {point.percentage:.2f}"
}

This will give you the percentage value



来源:https://stackoverflow.com/questions/11881032/number-formatting-at-highcharts-chart-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!