I am trying to replicate following chart:
So I want to have labels for the bars, but also another series as a text, which are the differences from previous month (the numbers in the brackets). So far, I have not been able to add these "extra" labels to the chart.
here is my sample code https://jsfiddle.net/hyj13Ltb/ :
// Define chart options
var options = {
chart: {
type: 'bar'
},
title: {
text: 'Sales by Product'
},
xAxis: {
categories: ['RO', 'RS', 'HU']
},
yAxis: {
title: {
text: 'Sales (USD)'
}
},
series: [{
name: 'Sales',
data: [110, 122, 133],
dataLabels: {
enabled: true
}
}, {
name: 'Difference from last month',
data: [-10, 45, 23],
color: 'gray',
showInLegend: false,
visible: false,
dataLabels: {
enabled: true,
inside: false,
align: 'left',
color: 'gray'
}
}]
};
// Initialize chart
Highcharts.chart('container', options);
2
Answers
We can display additional info next to point if we need. We can pass series data in the form of object and can have custom keys for our custom data. Then using format option we can format the data the way we want.
Here is an example.
You can refer to the API docs for more details:
https://api.highcharts.com/highcharts/series.bar.dataLabels.formatter
You can use one series (with data structure suggested by @CodeThing) and multiple data-labels. For example:
Live demo: https://jsfiddle.net/BlackLabel/4yt0jo5w/
API Reference: https://api.highcharts.com/highcharts/series.bar.dataLabels