I am working on a basic 1-series bar chart with nominal values for each bar. While I am able to plot it with data labels and axis showing the value of each bar, my goal is to display the percentage of the total series on these labels while keeping the nominal value in a tooltip upon hover (so I prefer not to convert the data to percentages before plotting).
Here's an illustration of what I want to achieve along with my current progress:
This is how I currently set up the axis labels using the formatter function:
plotOptions: {
bar: {
dataLabels: {
enabled: true,
formatter: function(){
return Highcharts.numberFormat(this.y,0);
}
}
}
}
Is there a specific formatter
variable that can help me accomplish this? I know pie charts allow for this easily, but I believe bar charts convey data more effectively.
EDIT: In simple terms, how can I calculate the sum of all points in the series? Once I have this, calculating the percentage becomes straightforward:
return Highcharts.numberFormat(100 * this.y / this.y.total,0) + "%";
where this.y.total
represents the series total sum.