I have a highchart pie chart but it does not display all the data labels. it only displays the dataLabels of the larger slices. i want the chart to display all the data labels even the ones for the smaller slices.
is there a way to format the chart to see all the data labels? can anyone please help with this?
example code
function generatePieData(numPieces) {
let data = [];
for (let i = 1; i <= numPieces; i++) {
let piece = {
y: i
};
data.push(piece);
}
return data;
}
Highcharts.chart('container', {
chart: {
type: 'pie'
},
title: {
text: ''
},
series: [{
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
},
borderWidth: 0,
borderRadius: 0,
data: generatePieData(100)
}]
});```
2
Answers
When there is insufficient space, Highcharts will selectively display data labels to ensure the chart remains legible. By default, each data label includes padding, and if it overlaps with another label, it gets concealed. To display all data labels, you must adjust the padding to 0.
So in your code add padding: 0 in dataLabels like this:
hope this helps !
I recommend reading the related GitHub thread:
https://github.com/highcharts/highcharts/issues/7907
You might explore one of the solutions provided in the thread. Additionally, you can experiment with various options such as
dataLabels.distance
,pie.center
,pie.size
, and the font size of dataLabels.Demo:
https://jsfiddle.net/BlackLabel/9arpx4bt/