Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
105
rated 0 times [  106] [ 1]  / answers: 1 / hits: 35030  / 10 Years ago, tue, september 30, 2014, 12:00:00

I'm using Highcharts to generate a line chart that shows currency values. By default the y-axis labels use metric prefixes for abbreviation, e.g. 3k is displayed instead of 3000



I would like to prepend a currency symbol to these labels, e.g. display $3k instead of 3k. However as soon as I add the currency symbol, the metric prefixes are no longer used. I've tried the following



    yAxis: {
labels: {
formatter: function () {
return '$' + this.value;
}
}
}


and also tried



    yAxis: {
labels: {
format: '${value}'
}
}


But in both cases $3000 is displayed instead of $3k. Is it possible to add a currency symbol without losing the metric prefix?



Here's a demo (JSFiddle here) that illustrates the problem





$(function() {
$('#container').highcharts({

yAxis: {
// if you include the lines below, the metric prefixes disappear
/*
labels: {
format: '${value}'
}
*/
},

series: [{
data: [15000, 20000, 30000]
}]

});
});

<script src=https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js></script>
<script src=https://code.highcharts.com/highcharts.js></script>

<div id=container style=height: 400px; width: 500px></div>




More From » highcharts

 Answers
8

You can call the original formatter from your formatter function:



$(function () {
$('#container').highcharts({

yAxis: {
labels: {
formatter: function () {
return '$' + this.axis.defaultLabelFormatter.call(this);
}
}
},

series: [{
data: [15000, 20000, 30000]
}]

});
});


http://jsfiddle.net/x6b0onkp/2/


[#69287] Saturday, September 27, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daijac

Total Points: 568
Total Questions: 120
Total Answers: 108

Location: Virgin Islands (U.S.)
Member since Fri, May 7, 2021
3 Years ago
daijac questions
Fri, Feb 25, 22, 00:00, 2 Years ago
Mon, Aug 3, 20, 00:00, 4 Years ago
Sun, Jun 7, 20, 00:00, 4 Years ago
;