Chart.js 3.7.1 - 如何控制折线图 y 轴上的刻度数?
数据始终是 -10 到 10 之间的整数,包括 0,因此 y 轴上最多可以有 21 个“间隔”。
无论数据如何,我都需要 y 轴以 1 为增量显示从 -10 到 10(包括 0)。因此,无论数据如何,我都需要 y 轴上总共 21 个(刻度?)。
我根据文档尝试了这个: 我也尝试过没有步骤参数:
options: {
scales: {
y: {
max: -10,
min: 10,
ticks: {
steps: 21,
stepSize: 1
}
}
}
}
The data will always be integers between -10 and 10, including 0 so there could be a maximum of 21 'intervals' on the y axis.
Regardless of the data, I need the y axis to display from -10 to 10 (including 0) in increments of 1. So I need a total of 21 (ticks?) on the y axis regardless of the data.
I tried this, per the docs:
I also tried it without the steps param:
options: {
scales: {
y: {
max: -10,
min: 10,
ticks: {
steps: 21,
stepSize: 1
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
代码中缺少的部分是
autoSkip: false
。请看一下下面的可运行代码并了解它是如何工作的。
The missing part in your code is
autoSkip: false
.Please take a look at below runnable code and see how it works.
您可以使用以下代码管理刻度计数:
you can manage ticks count with this code: