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/
[[edit for comments
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;
}
return total;
}
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) + '%';
}
}
Source: stackoverflow.com
Related Query
- Highcharts percentage of total for simple bar chart
- Simple bar chart in jQuery HighCharts and MVC 2 application?
- Importing JSON file into Highcharts for Bar Chart Visualization
- Passing in Id for each data item in bar chart using highcharts
- Splitted bar chart for paired data with highcharts
- highcharts minPointLength do not work for unstacked bar chart
- How to change color of bar in column chart with different level of percentage in highcharts
- Highcharts display label for pie chart using html table as data source
- Highcharts stacked bar chart for multiple bars
- set individual color for each bar in bar chart using highcharts
- Displaying count on bar and percentage on Y-axis of cloumn chart using Highcharts
- Cannot set bar chart width for specific data, Highcharts
- Unresponsive Script and/or high response time for bar chart using HighCharts
- HighCharts Create gradiance decress color to blur for each value on bar chart
- How to create a legend for bar colors in a Highcharts bar chart
- dataLabels for bar chart in Highcharts not displaying for null values in 3.0.8
- Highcharts - PDF export format; font sizes for bar chart axis
- modifying Highcharts tool tip with for a bar chart dynamic data
- HighCharts turn animation false for line chart
- How to display the value instead of percentage in a pie chart using jquery Highcharts
- How do I rotate my HighCharts bar chart so its vertical, not horizontal?
- Displaying percentage inside pie item for highcharts
- dealing with highcharts bar chart with really long category names
- Displaying percentage in Y-axis of Highcharts column chart
- HighCharts - Y-Axis padding in a bar chart
- Highcharts not displaying data labels for Pie chart in arabic
- highcharts jquery dynamic change chart type column to bar
- Total of values in HighCharts Pie Chart
- highcharts - chart names for multiple pie chart series in one chart
- HighCharts-Removing the padding for a bar chart
More Query from same tag
- Highcharts legends are overlapping when i change language to arabic
- Setting Flag on Click Event for Candlestick Chart
- Increasing the length of widgetboxes sDashboard
- PHP and Highcharts
- Highcharts - how to toggle datalabels via js?
- Wrapping a HighChart in AngularJS
- HighChart Bubble and Date / Tooltip
- Highchart - Use a formatter on PlotLine labels
- How to add the "isSum" bar in Highchart Waterfall chart in R?
- iScroll 4 and highcharts compatibility issue
- Difference between setExtremes and afterSetExtremes in HighStock
- High Charts PieChart How Can I show point value inside segment and label name outside
- if I add an update in drill up events it causes the labels to disappear on the highchart
- highcharts clickable labels how to goto anchor
- Highchart Data is not supporting
- How do I escape a single quote using C# string.Replace to use in HighCharts?
- highcharts can't work in website
- Highcharts Server side generation not working on windows 2008 server
- Highchart- Using PHP, MYSQL and jQuery.get to parse data
- Highcharts setExtremes() does not display the correct interval for one day
- Highcharts heatmap with custom colors for each yAxis
- Highcharts y axis thousands separator
- Make Highchart and Highstock Have a Uniform Time X-Axis for Disparate Data Points
- Width of column in columnchart using highcharts
- Highchart X-Axis Label DateTime Issue
- highcharts - pulling data from HTML but converting the strings to number
- HighCharts: 3D Column Chart change borderColor on select
- Define and apply theme on highcharts-react-official
- Highcharts with ajax/ json and SQL Server ASP.NET
- Highcharts: adding extra data to drilldown