Charts.js Formatting Y Axis with both Currency and Thousands Separator(Charts.js 使用货币和千位分隔符格式化 Y 轴)
问题描述
我正在使用 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/
这篇关于Charts.js 使用货币和千位分隔符格式化 Y 轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Charts.js 使用货币和千位分隔符格式化 Y 轴


- Fetch API 如何获取响应体? 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Flexslider 箭头未正确显示 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 400或500级别的HTTP响应 2022-01-01