我在玩 chartsJS,我想做 2 种格式化事情。每个格式化的东西单独工作,但当我一起做时不起作用。
格式 1:将 Y 轴设置为从 0 开始。我是这样做的:
options: {
title: {
display: true,
text: 'Number of faults'
},
responsive: false,
scales: {
yAxes: [{
display: true,
ticks: {
beginAtZero: true,
min: 0
}
}]
},
格式 2:添加轴标签:
options = {
scales: {
yAxes: [{
scaleLabel: {
display: true,
labelString: 'probability'
}
}]
}
}
但是当我尝试同时执行这两项操作时,它不起作用:
options: {
title: {
display: true,
text: 'Number of faults'
},
responsive: false,
scales: {
yAxes: [{
display: true,
labelString: 'probability'
ticks: {
beginAtZero: true,
min: 0
}
}]
},
}
答案 0 :(得分:1)
您忘记再次将 labelstring
放在 scaleLabel
属性中以用于组合配置,如果您这样放置它应该可以工作:
options: {
title: {
display: true,
text: 'Number of faults'
},
responsive: false,
scales: {
yAxes: [{
scaleLabel: {
display: true,
labelString: 'probability'
},
ticks: {
beginAtZero: true,
min: 0
}
}]
},
}