Displaying percentage inside pie item for highchar

2019-03-14 17:43发布

I am trying to figure out if it is possible to display the percentage for each pie item inside the actual pie item for highcharts? Example of what I mean is something like this:

https://developers.google.com/chart/interactive/docs/gallery/piechart

3条回答
三岁会撩人
2楼-- · 2019-03-14 18:14

Its suprisingly easy. In your tooltip or dataLabels section change your format.

FROM:
  format: '<b>{point.name}</b>: {point.y:.1f} Rs.',
TO:
  format: '<b>{point.name}</b>: {point.percentage:.1f} %',
查看更多
再贱就再见
3楼-- · 2019-03-14 18:17

Try this code. It works for me:

  'labelFormatter':function () { 
       var total = 0, percentage; 
       $.each(this.series.data, function() { 
          total+=this.y; 
       }); 

       percentage=((this.y/total)*100).toFixed(1); 
       return this.name+' '+percentage+'%'; 
    }
查看更多
够拽才男人
4楼-- · 2019-03-14 18:22

You may want to look @ dataLabels.formatter. this.percentage option is available for pie

Also dataLabels.distance can be set to a negative value for dataLabels inside the pie.

Pie with percentage values inside @ jsFiddle

查看更多
登录 后发表回答