1 回答

TA貢獻(xiàn)1909條經(jīng)驗(yàn) 獲得超7個(gè)贊
ticks您可以通過(guò)如下定義來(lái)偽造零線的刻度:
ticks: {
min: 0.65,
stepSize: 0.1,
callback: (value, index, values) => index + 1 == values.length ? 0 : value
}
如需進(jìn)一步說(shuō)明,請(qǐng)查看從 Chart.js 文檔創(chuàng)建自定義刻度格式。
請(qǐng)看一下下面的可運(yùn)行代碼,看看它是如何工作的。
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>
添加回答
舉報(bào)