我正在使用来自Highcharts的饼图并且工作正常,但我要求显示百分比值,如下图所示。
我尝试使用legand选项但是没有用。
我的设置如下。
$('#' + source).highcharts({
credits: {
enabled: false
},
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: chartTitle
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: false,
cursor: 'pointer',
dataLabels: {
enabled: false,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
},
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
},
connectorColor: 'silver',
showInLegend: true
}
},
legend: {
enabled: true,
layout: 'horizontal',
verticalAlign: 'bottom',
adjustChartSize: true
},
series: [{
name: 'Total of ',
colorByPoint: true,
data: chartData
}]
});
答案 0 :(得分:1)
答案 1 :(得分:0)
答案 2 :(得分:0)
获取dataLabels
及其distance
属性和formatter
功能的帮助。使用此fiddle:
<强> JS:强>
var container = new Highcharts.Chart('container',{
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: 'Current Asset Allocation',
style: {
fontSize: '17px',
color: 'red',
fontWeight: 'bold',
fontFamily: 'Verdana'
}
},
subtitle: {
text: '(As of ' + 'dfdf' + ')',
style: {
fontSize: '15px',
color: 'red',
fontFamily: 'Verdana',
marginBottom: '10px'
},
y: 40
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage}%</b>',
percentageDecimals: 0
},
plotOptions: {
pie: {
size: '80%',
cursor: 'pointer',
data: [
['Investment Grade Bonds', 100],
['High Yield Bonds', 200],
['Hedged Equity', 300],
['Global Equity', 400],
['Cash', 500]
]
}
},
series: [{
type: 'pie',
name: 'Asset Allocation',
dataLabels: {
verticalAlign: 'top',
enabled: true,
color: '#000000',
connectorWidth: 1,
distance: -30,
connectorColor: '#000000',
formatter: function() {
return Math.round(this.percentage) + ' %';
}
}
}, {
type: 'pie',
name: 'Asset Allocation',
dataLabels: {
enabled: true,
color: '#000000',
connectorWidth: 1,
distance: 30,
connectorColor: '#000000',
formatter: function() {
return '<b>' + this.point.name + '</b>:<br/> ' + Math.round(this.percentage) + ' %';
}
}
}],
exporting: {
enabled: false
},
credits: {
enabled: false
}
});
<强> HTML:强>
<div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>