While attempting to implement a pie chart using Highcharts, I have encountered an issue with the datalabels getting cropped on very low resolutions.
I tried adding a windows.resize within the formatter function but it did not work.
Below is the current code snippet I am using:
// Radialize the colors
Highcharts.getOptions().colors = $.map(Highcharts.getOptions().colors, function (color) {
return {
radialGradient: { cx: 0.5, cy: 0.3, r: 0.7 },
stops: [
[0, color],
[1, Highcharts.Color(color).brighten(-0.3).get('rgb')] // darken
]
};
});
// Build the chart
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
backgroundColor: {
linearGradient: [0, 0, 500, 500],
stops: []
},
},
title: {
text: 'Header Here'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage}%</b>',
percentageDecimals: 0
},
plotOptions: {
pie: {
allowPointSelect: false,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ Math.round(this.percentage) +'%';
}
}
}
},
series: [{
type: 'pie',
name: 'Votes',
data: [
['Vote One', 50],
['Vote Two', 50],
['Vote three', 2]
]
}]
});
Is there any other way besides creating a new chart on resize to hide or show the labels based on resolution?
Thank you.