score:28

you'll have to loop through the data and get the total, and then use the datalabel formatter function to get the percent.

example here:

http://jsfiddle.net/jvnjs/319/

``````formatter:function() {
var pcnt = (this.y / datasum) * 100;
return highcharts.numberformat(pcnt) + '%';
}
``````

edit::

updated example with axis labels:

http://jsfiddle.net/jvnjs/320/

if you are trying to plot the percent values of multiple series, there are a variety of fundamental problems that arise.

if you are calculating the % of two different data series, and displaying the % value even though you've plotted the raw value, your chart will be misleading and confusing in most cases.

plotting the data as the percent values directly is the best way to go in that case, and you can add the raw data value as an extra property in the point object if you want to display it in a tool tip or elsewhere ( ie http://jsfiddle.net/jvnjs/735/ )

if you insist on using the original method on two different series, then you can just create two different variables to calculate against, and check the series name in the formatter to determine which data sum to calculate against.

score:-1

try this.percentage

it's pretty well documented in the highcharts api as well.

http://api.highcharts.com/highcharts#plotoptions.series.datalabels.formatter

edit

since you'd need it for non-stacked series, you'd need to get the total before generating the graph... the function below adds up your values into one variable which you can use in your formatter function later.

``````function arraytotal(arr)
{
var total = 0;
for (var i = 0, value; value = arr[i]; i++)
{
total += value;
}
}
``````

score:-1

highchart library is very enrich with build in functions. if you would like to just for the number on chart up to certain number. you can give a try for below function.

``````import {numberformat} from 'hicghart';

then you can achieve the below way formating

numberformat(this.y,decimalplacetoformat)
``````

score:4

@jlbriggs had a great answer and lead me onto the path of creating this formatter function. this function always checks the current values in the data. if the data is updated programmatically at a later time, the percentages will reflect the newly updated data. no `datasum` or loop is necessary as the `.map().reduce()` takes care of that for you.

``````datalabels: {
enabled: true,
formatter: function() {
var pcnt = (this.y / this.series.data.map(p => p.y).reduce((a, b) => a + b, 0)) * 100;
return highcharts.numberformat(pcnt) + '%';
}
}
``````