Charts.js 使用货币和千位分隔符格式化 Y 轴货币、分隔符、Charts、js

由网友(即刻称王_)分享简介:我正在使用 Charts.js 在我的网站上显示图表.目前,标签显示为一长串数字(即 123456).我希望它显示为带有千位分隔符的货币:(即 $123,456)I'm using Charts.js to show a graph on my site. Currently, the label shows as...

我正在使用 Charts.js 在我的网站上显示图表.目前,标签显示为一长串数字(即 123456).我希望它显示为带有千位分隔符的货币:(即 $123,456)

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)

我正在使用 scaleLabel 选项在值之前放置一个 $ USD 符号:

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.

这里是小提琴:http://jsfiddle.net/vy0yhd6m/79/

(请记住,目前该图表只有在您删除上面引用的这两个 JavaScript 片段之一时才能工作)

感谢您的任何帮助.

推荐答案

你应该能够在函数内部的标签组合中包含货币前缀...

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/

阅读全文

相关推荐

最新文章