Chart.js 2.0 Formatting Y Axis with Currency and Thousands Separator(Chart.js 2.0 使用货币和千位分隔符格式化 Y 轴)
问题描述
我在格式化图表轴时遇到问题,我找不到更新版本 2.0 的示例.
I am having problems with formatting my chart axis and I am not able to find an example for the updated version 2.0.
我怎样才能(例如)赚到 2000000 到 2.000.000 欧元?
How can I (for example) make 2000000 to €2.000.000?
我的小提琴:https://jsfiddle.net/Hiuxing/4sLxyfya/4/
window.onload = function() {
var ctx = document.getElementById("canvas").getContext("2d");
window.myBar = new Chart(ctx, {
type: 'bar',
data: barChartData,
options: {
title: {
display:true,
text:"Figure"
},
legend: {
position: "bottom"
},
tooltips: {
mode: 'label',
bodySpacing: 10,
cornerRadius: 0,
titleMarginBottom: 15
},
scales: {
xAxes: [{
ticks: {}
}],
yAxes: [{
ticks: {
beginAtZero: true,
stepSize: 500000
}
}]
},
responsive: true
}
});
};
推荐答案
修复
在创建配置对象时将函数分配给 userCallback.创建刻度线时会调用它.您可以在 Scales 文档底部的 Chart.js
修复问题的示例
yAxes: [{
ticks: {
beginAtZero: true,
stepSize: 500000,
// Return an empty string to draw the tick line but hide the tick label
// Return `null` or `undefined` to hide the tick line entirely
userCallback: function(value, index, values) {
// Convert the number to a string and splite the string every 3 charaters from the end
value = value.toString();
value = value.split(/(?=(?:...)*$)/);
// Convert the array to a string and format the output
value = value.join('.');
return '€' + value;
}
}
}]
这篇关于Chart.js 2.0 使用货币和千位分隔符格式化 Y 轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Chart.js 2.0 使用货币和千位分隔符格式化 Y 轴
基础教程推荐
- 如何添加到目前为止的天数? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
