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 轴
基础教程推荐
- 每次设置弹出窗口的焦点 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
