Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
134
rated 0 times [  138] [ 4]  / answers: 1 / hits: 94077  / 10 Years ago, sun, february 15, 2015, 12:00:00

I'm using Charts.js to show a graph on my site. Currently, the label shows as a long string of numbers (i.e 123456).
I want it to show as currency with thousands separator: (i.e $123,456)



I'm using the scaleLabel option to put a $ USD symbol before the value:



scaleLabel: <%= ' $' + Number(value)%>


and a function to insert the comma separator:



function(label){return label.value.toString().replace(/B(?=(d{3})+(?!d))/g, ,);}


I just do not know how to use these together to get what I want.



Here is the fiddle: http://jsfiddle.net/vy0yhd6m/79/



(please keep in mind that currently the graph will only work if you remove one of those two pieces of JavaScript cited above)



Thank you for any and all help.


More From » function

 Answers
74

You should be able to include currency prefix in composition of label inside function...



var options = {
animation: false,
scaleLabel:
function(label){return '$' + label.value.toString().replace(/B(?=(d{3})+(?!d))/g, ,);}
};


http://jsfiddle.net/vy0yhd6m/80/


[#67819] Thursday, February 12, 2015, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
meadowe

Total Points: 0
Total Questions: 97
Total Answers: 97

Location: Laos
Member since Fri, Sep 11, 2020
4 Years ago
meadowe questions
Thu, Aug 5, 21, 00:00, 3 Years ago
Thu, Jul 9, 20, 00:00, 4 Years ago
Mon, Jun 8, 20, 00:00, 4 Years ago
Sun, Feb 9, 20, 00:00, 4 Years ago
;