我正在使用http://www.chartjs.org/上的折线图
正如你可以看到Y轴的最大值(130)和最小值(60)是自动选择的,我想要最大值= 500和最小值=0。这可能吗?
我正在使用http://www.chartjs.org/上的折线图
正如你可以看到Y轴的最大值(130)和最小值(60)是自动选择的,我想要最大值= 500和最小值=0。这可能吗?
当前回答
v3。X (v3.5.0)
线性笛卡尔轴
let options = {
scales: {
y: {
beginAtZero: true,
suggestedMax: 69
},
x: {
beginAtZero: true,
suggestedMax: 420
},
ticks: {
stepSize: 1
}
}
}
引用https://www.chartjs.org/docs/3.5.0/axes/cartesian/linear.html
线性径向轴
let options = {
scales: {
r: {
beginAtZero: true,
suggestedMax: 5,
ticks: {
stepSize: 1
}
}
}
}
引用https://www.chartjs.org/docs/3.5.0/axes/radial/linear.html
v2。X (v2.9.4)
线性笛卡尔轴
let options = {
scale: {
ticks: {
beginAtZero: true,
stepSize: 1,
suggestedMax: 5,
}
}
}
引用https://www.chartjs.org/docs/2.9.4/axes/cartesian/linear.html
线性径向轴
let options = {
scale: {
ticks: {
beginAtZero: true,
stepSize: 1,
suggestedMax: 5,
}
}
}
引用https://www.chartjs.org/docs/2.9.4/axes/radial/linear.html
注:v2为单数,v3为复数
其他回答
对于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
只需在选项中设置scaleStartValue的值。
var options = {
// ....
scaleStartValue: 0,
}
请在这里查看相关文档。
编辑:
他们做了一些改变。目前,这是可行的
scales: {
x: {
...,
max: value,
min: value
},
y: {
...same as x
}
}
这里是最新变化的链接 最小最大图表js
旧的回答:
截至2022年2月,这是有效的。以下是一个人可以改变它的方法
var options = {
scales: {
yAxes: [{
display: true,
stacked: true,
ticks: {
min: 0, // minimum value
max: 10 // maximum value
}
}]
}
};
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
window.onload = function(){
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = new Chart(ctx ,{
type: 'line',
data: yourData,
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true,
min: 0,
max: 500
}
}]
}
}
});
我在v2中配置了“选项”。
你应该阅读文档: http://www.chartjs.org/docs/#scales-linear-scale