Dam*_*nni 5 javascript chart.js chartjs-2.6.0
我使用带有3个Y轴的chart.js创建了一个简单的折线图:https ://codepen.io/anon/pen/dZVgKw
如您所见,最后一个数字是10到20,中间没有任何数字。如何在此处设置步长?
这是我添加斧头的方式:
{
id: 'C',
type: 'linear',
position: 'left',
ticks: {
max: 10,
min: 20,
},
}
Run Code Online (Sandbox Code Playgroud)
谢谢。
Nik*_*des 20
我如何在这里设置步长?
直接来自样本(线性比例,步长):
通过设置一个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
}
}]
}
Run Code Online (Sandbox Code Playgroud)
这是一个活生生的例子:
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
}
}]
}
Run Code Online (Sandbox Code Playgroud)
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
},
}]
}
}
})Run Code Online (Sandbox Code Playgroud)