ChartJS:如何设置固定 Y 轴最大值和最小值 [英] ChartJS: How to set fixed Y axis max and min
问题描述
我有一个折线图,我正在尝试设置 固定 最大值和最小值.我已经尝试过在 SO 上找到的其他建议,但它仍然不起作用.我的图表会根据传入的数据不断重新设置最大值和最小值.
I have a line chart which I'm trying to set a fixed max and min values. I have tried the other suggestions found on SO, but it still doesn't work. My chart keeps re-setting the max and min values depending on the incoming data.
这是我传递给折线图的当前选项:
Here's my current options that I pass to my Line chart:
var options = {
responsive: true,
animation: false
};
我也尝试了这些设置:
var options = {
scales: {
animation: false,
yAxes: [{
display: true,
ticks: {
suggestedMin: -1,
suggestedMax: 1
}
}]
}
};
知道我做错了什么吗?
谢谢!
推荐答案
要修复 yAxes 比例的最小值和最大值,请使用以下代码.
To fix min and max value for yAxes scale use the below code.
options:{
scales: {
yAxes : [{
ticks : {
max : 1,
min : -1
}
}]
}
}
suggestedMax 仅在传入数据低于建议最大值时才有效.suggestedMin 仅在传入数据大于建议的最小值时起作用.
suggestedMax will only works when incoming data is lower than suggestedMax value. suggestedMin will works only when incoming data is greater than suggestedMin value.
这篇关于ChartJS:如何设置固定 Y 轴最大值和最小值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!