Chart.js - 格式化 Y 轴 [英] Chart.js - Formatting Y axis
本文介绍了Chart.js - 格式化 Y 轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Chart.js 来绘制一个简单的条形图,我需要像这样格式化它的 Y 轴
I'm using Chart.js to draw a simple bar plot and I need to format its Y axis like
123456.05 至 123 456,05 美元
123456.05 to 123 456,05 $
我不明白如何使用 scaleLabel : "<%=值%>"
I don't understand how to use scaleLabel : "<%=value%>"
我看到有人指向JS 微模板",
但不知道如何将它与我们的 scaleLabel
选项一起使用.
I saw someone pointing to "JS Micro-Templating",
but no clue how to use that with our scaleLabel
option.
有人知道如何格式化这个 Y 轴吗,也许能给我一个例子?
Does someone know how to format this Y axis, and maybe give me an example ?
推荐答案
我也遇到了同样的问题,我认为在 Chart.js 2.xx 中的方法略有不同,如下所示.
I had the same problem, I think in Chart.js 2.x.x the approach is slightly different like below.
ticks: {
callback: function(label, index, labels) {
return label/1000+'k';
}
}
更多细节
var options = {
scales: {
yAxes: [
{
ticks: {
callback: function(label, index, labels) {
return label/1000+'k';
}
},
scaleLabel: {
display: true,
labelString: '1k = 1000'
}
}
]
}
}
这篇关于Chart.js - 格式化 Y 轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文