I'm trying to put a label within a bar chart in Highcharts. In my case above each bar which you can see here:
$(function () {
var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'column'
},
title: {
text: 'Indicator per Sex'
},
xAxis: {
categories: [
'Jan',
'Fev',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dez'
]
},
yAxis: {
allowDecimals: false,
min: 0,
title: {
text: 'Consults'
}
},
tooltip: {
formatter: function() {
return '<b>'+ this.x +'</b><br/>'+
this.series.name +': '+ this.y +'<br/>'+
'Total: '+ this.point.stackTotal;
}
},
plotOptions: {
column: {
stacking: 'normal'
}
},
series: [
{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 29.9, 71.5, 106.4, 129.2, 144.0, 10, 20],
color: '#FF0011',
stack: 0
}, {
data: [30, 176.0, 135.6, 148.5, 216.4, 29.9, 71.5, 106.4, 129.2, 144.0, 10, 20],
color: '#3333FF',
stack: 0
}, {
data: [29.9, 71.5, 106.4, 129.2, 144.0, 29.9, 71.5, 106.4, 129.2, 144.0, 10, 20],
color: '#FF0011',
stack: 1
}, {
data: [30, 176.0, 135.6, 148.5, 216.4, 29.9, 71.5, 106.4, 129.2, 144.0, 10, 20],
color: '#3333FF',
stack: 1
}, {
data: [29.9, 71.5, 106.4, 129.2, 144.0, 29.9, 71.5, 106.4, 129.2, 144.0, 10, 20],
color: '#FF0011',
stack: 2
}, {
data: [30, 176.0, 135.6, 148.5, 216.4, 29.9, 71.5, 106.4, 129.2, 144.0, 10, 20],
color: '#3333FF',
stack: 2
}]
});
});
});`
I tried, but when I add labels appear one label each bar. So, how do this?!
add this to your series:
dataLabels: {
enabled: true,
rotation: 0,
color: '#000000',
backgroundColor: '#FFFFFF',
align: 'center',
x: 4,
y: 0,
style: {
fontSize: '10px',
fontFamily: 'Verdana, sans-serif'
}
of course adjust as needed..
you can also add a formatter
to add $ sign and commas for large numbers if you need it..
EDIT:
just saw it was bar chart..
you will need to add this to your plot options:
plotOptions: {
bar: {
dataLabels: {
enabled: true
}
}
},
check out the bar chart demo as well as their api documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With