I want to prefix a $ to the default y-axis label. My bar chart is using values in the millions so the chart is returning value-MM (80MM, 30MM). What I would like to do is format the y-axis like $-value-MM ($80MMm $30MM). I have tried the code below and can't get it to work?
yAxis: [{ // Primary yAxis
labels: {
formatter: function () {
return '$' + this.value;
}
},
title: {
text: 'Revenue',
If I understand the question correctly, your data already has 'MM' suffix and you want to add the prefix '$'.
Try,
One rather elaborate way to achieve this is to re-use the code Highcharts uses in their internal
defaultLabelFormatter
for axis that are numeric, and use it in the axis formatter.An example of this, with your added prefix (JSFiddle):
A experimental short form of this would be to call the
defaultLabelFormatter
with the essential parts of the context it requires. An example of this (JSFiddle):As the context is incomplete it wouldn't work as expected if your axis was
datetime
orcategories
or perhaps logarithmical, but should work for numeric axis. For the full picture I suggest looking at the fulldefaultLabelFormatter
implementation.