'Chart js data to start at zero
That's how I set the data:
const data = {
labels: ['February', 'March'],
datasets: [
{
label: 'My First dataset',
backgroundColor: 'rgba(255,99,132,0.2)',
borderColor: 'rgba(255,99,132,1)',
borderWidth: 1,
hoverBackgroundColor: 'rgba(255,99,132,0.4)',
hoverBorderColor: 'rgba(255,99,132,1)',
data: [5, 9]
}
]
};
But the first element sets the beginning of the axis:
But I want it to start from zero
adding the following doesn't help:
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
I couldn't find another setting to do that on the docs.
I'm using this btw: https://www.npmjs.com/package/react-chartjs-2
Solution 1:[1]
Try Adding min to your options:
var options = {
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
min: 0
}
}]
}
};
Live Copepen: Chart.js Start at zero
Solution 2:[2]
Replaced by:
const options = {
scales: {
y: {
beginAtZero: true
}
}
};
It worked!
Solution 3:[3]
As per chart.js 3.7.1 version
Directly write "beginAtZero" in x or y not in ticks
const options = {
scales: {
x: {
beginAtZero: true,
},
y: {
beginAtZero: true,
}
}
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Keno |
| Solution 2 | LTL |
| Solution 3 | sidd 5312 |


