Javascript 在 highcharts 的饼图中显示百分比
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12529934/
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
Displaying percentage inside pie item for highcharts
提问by ryanzec
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:
我想弄清楚是否可以在 highcharts 的实际馅饼项目中显示每个馅饼项目的百分比?我的意思的例子是这样的:
https://developers.google.com/chart/interactive/docs/gallery/piechart
https://developers.google.com/chart/interactive/docs/gallery/piechart
回答by Jugal Thakkar
You may want to look @ dataLabels.formatter
. this.percentage
option is available for pie
你可能想看看 @ dataLabels.formatter
。this.percentage
选项可用于馅饼
Also dataLabels.distance
can be set to a negative value for dataLabels inside the pie.
也dataLabels.distance
可以将饼图内的 dataLabels 设置为负值。
回答by Mark
Its suprisingly easy. In your tooltip or dataLabels section change your format.
它非常容易。在您的工具提示或 dataLabels 部分更改您的格式。
FROM:
format: '<b>{point.name}</b>: {point.y:.1f} Rs.',
TO:
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
回答by Sarvar Nishonboev
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+'%';
}