gpt4 book ai didi

javascript - 如何在 Chart.js 2 中设置轴的步长?

转载 作者:搜寻专家 更新时间:2023-11-01 04:13:14 25 4
gpt4 key购买 nike

我使用带有 3 个 Y 轴的 chart.js 创建了一个简单的折线图: https://codepen.io/anon/pen/dZVgKw

如您所见,最后一个是从 10 到 20,中间没有任何数字。如何在这里设置步长?

这是我添加斧头的方式:

{
id: 'C',
type: 'linear',
position: 'left',
ticks: {
max: 10,
min: 20,
},
}

谢谢。

最佳答案

How can I set step size here?

直接来自 samples (Linear Scale, step size) :

通过设置一个 stepSize 值。

scales: {
xAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Month'
}
}],
yAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Value'
},
ticks: {
min: 0,
max: 100,

// forces step size to be 5 units
stepSize: 5 // <----- This prop sets the stepSize
}
}]
}

这是一个活生生的例子:

var ctx = document.getElementById('chartJSContainer').getContext('2d')

new Chart(ctx, {
type: 'line',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [
{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderWidth: 1
},
{
label: '# of Points',
data: [7, 11, 5, 8, 3, 7],
borderWidth: 1
}
]
},
options: {
scales: {
yAxes: [{
ticks: {
reverse: false,
stepSize: 3
},
}]
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.js"></script>
<body>
<canvas id="chartJSContainer" width="600" height="400"></canvas>
</body>

关于javascript - 如何在 Chart.js 2 中设置轴的步长?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47334236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com