Displaying percentage inside pie item for highcharts

泄露秘密 提交于 2019-12-20 11:36:18

问题


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


回答1:


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




回答2:


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:


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+'%'; 
    }


来源:https://stackoverflow.com/questions/12529934/displaying-percentage-inside-pie-item-for-highcharts

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