我正在使用http://www.chartjs.org/上的折线图
正如你可以看到Y轴的最大值(130)和最小值(60)是自动选择的,我想要最大值= 500和最小值=0。这可能吗?
我正在使用http://www.chartjs.org/上的折线图
正如你可以看到Y轴的最大值(130)和最小值(60)是自动选择的,我想要最大值= 500和最小值=0。这可能吗?
当前回答
从最新版本v3.9.1开始,你可以像这样设置你的比例:
options:{
scales:{
y:{
beginAtZero: true,
max: 500 // values over 500 will be hidden, OR
suggestedMax: 500, // maximum will be 500, unless there is a higher value
}
}
}
其他回答
从最新版本v3.9.1开始,你可以像这样设置你的比例:
options:{
scales:{
y:{
beginAtZero: true,
max: 500 // values over 500 will be hidden, OR
suggestedMax: 500, // maximum will be 500, unless there is a higher value
}
}
}
上面的答案对我不起作用。可能从11年起,选项名称就发生了变化,但以下内容对我来说是有用的:
ChartJsProvider.setOptions
scaleBeginAtZero: true
ChartJS v2.4.0
如2017年2月7日https://github.com/jtblin/angular-chart.js上的例子所示(因为这似乎是经常变化的):
var options = {
yAxes: [{
ticks: {
min: 0,
max: 100,
stepSize: 20
}
}]
}
这将导致5个y轴值如下所示:
100
80
60
40
20
0
对于Chart.js v3.2.0,这样做:
let options = {
scales: {
y: {
suggestedMin: 0,
suggestedMax: 69
},
x: {
suggestedMin: 0,
suggestedMax: 420
}
}
}
文档:https://www.chartjs.org/docs/latest/axes/ axis-range-settings
对于"chart.js": "^3.6.1",
options: {
scales: {
y: {
min: 0,
max: 100,
}
}
}