1 回答
TA贡献1909条经验 获得超7个赞
ticks您可以通过如下定义来伪造零线的刻度:
ticks: {
min: 0.65,
stepSize: 0.1,
callback: (value, index, values) => index + 1 == values.length ? 0 : value
}
如需进一步说明,请查看从 Chart.js 文档创建自定义刻度格式。
请看一下下面的可运行代码,看看它是如何工作的。
new Chart(document.getElementById("myChart"), {
type: "line",
data: {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [{
label: "APAC RE index",
data: [0.7, 0.8, 0.9, 1, 0.9, 0.8, 0.7],
fill: false,
borderColor: "rgb(255, 0, 0)"
}]
},
options: {
legend: {
display: false
},
scales: {
yAxes: [{
ticks: {
min: 0.65,
stepSize: 0.1,
callback: (value, index, values) => index + 1 == values.length ? 0 : value
}
}]
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<canvas id="myChart" height="90"></canvas>
添加回答
举报