![](/img/trans.png)
[英]CHART.JS How can I offset/move/adjust the labels on the y-axis to be in the middle of the gridlines instead of centered on the gridlines?
[英]How Can I Change the Y-axis labels to be shown as strings other than number in Chart.js?
我正在创建一个 chart.js 线图,其 -y 轴值高达近一百万。 y 轴上的值为 0 100000 200000 300000 400000 等等。 这可能会让人厌烦阅读,我想将这些数字更改为 100k 200k 300k 的字符串,同时仍保持与之前相同的值,只是在页面上显示不同的值。 这可能吗? 谢谢你
使用他们文档中的这个例子,而不是返回一个美元符号 + 值返回:(value/1000 + 'K')
options: {
scales: {
yAxes: [{
ticks: {
// Include a K in the ticks
callback: function(value, index, values) {
return (Number.parseInt(value)/1000) + 'K';
}
}
}]
}
}
https://www.chartjs.org/docs/latest/axes/labelling.html#creating-custom-tick-formats
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.