我从 ChartJs 2 升级到了 4。布局和刻度仍然不像以前那样。
这是旧版本 2(顶部)与新版本 4(底部)的比较
版本 4
这是我的图表配置代码:
options: {
legend: { display: false },
responsive: false,
maintainAspectRatio: false,
scales: {
x: {
type: "time",
distribution: "timeseries",
time: { parser: "YYYY-MM-DDTHH:mm", tooltipFormat: "ll" },
ticks: {
source: "data",
maxRotation: 90,
minRotation: 90,
autoSkip: false
}
},
y: { ticks: { beginAtZero: true, major: { enabled: true } , autoSkip: false } }
},
tooltips: {
callbacks: {
label: this.label || defaultLabel
}
},
}
这是每个线数据集的共享配置:
{
data: [],
backgroundColor: "#2bb2e7",
borderColor: "#2bb2e7",
color: '#000',
fill: false,
label: "",
pointRadius: 5,
pointHoverRadius: 20,
borderWidth: 3,
cubicInterpolationMode: 'monotone',
tension: 0.4
}
问题是:
如何控制“Y”轴上显示多少个刻度(版本 2 可以更好地自动计算多少个刻度)?
stepSize
您可以使用和来调整所需的刻度数maxTicksLimit
。作为参考,请在此处查看定义:
https://www.chartjs.org/docs/latest/api/#radialtickoptions