highcharts中如何在饼图中改变显示的占比位置
在Highcharts中,可以使用dataLabels属性来改变饼图中显示的占比位置。以下是一个示例代码:
Highcharts.chart('container', {
chart: {
type: 'pie'
},
title: {
text: 'Fruit Consumption'
},
plotOptions: {
pie: {
dataLabels: {
enabled: true,
distance: -30, // 设置占比标签的位置
format: '{point.percentage:.1f} %', // 设置占比标签的格式
style: {
fontWeight: 'bold',
color: 'white'
}
}
}
},
series: [{
name: 'Brands',
colorByPoint: true,
data: [{
name: 'Apple',
y: 61.41,
sliced: true,
selected: true
}, {
name: 'Banana',
y: 11.84
}, {
name: 'Orange',
y: 10.85
}, {
name: 'Mango',
y: 4.67
}, {
name: 'Grape',
y: 4.18
}]
}]
});
在上述代码中,dataLabels属性用于设置占比标签的样式和位置。distance属性用于设置占比标签距离饼图中心的距离,负值表示向内偏移。format属性用于设置占比标签的格式,{point.percentage:.1f} %表示保留一位小数的百分比形式。style属性用于设置占比标签的样式,例如字体加粗和颜色为白色。
通过调整distance属性的值,可以改变占比标签的位置
原文地址: https://www.cveoy.top/t/topic/hWAV 著作权归作者所有。请勿转载和采集!