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
Simple. Set the axis start point to zero (Select axis, press Ctrl+1, and from Axis options set minimum to 0). So there you go.
Data in a line chart is encoded by position (x, y coordinates), whereas in a bar chart data is represented by length. This subtle difference changes the way a reader uses the chart, meaning that in a line chart it's ok to start the axis at a value other than zero, despite many claims that they are always misleading.
To start the y-axis scale start from 0 you can use the beginAtZero property of Chart. js as shown in the below example. Here we have used beginAtZero: true property of Chart. js to set the minimum scale value to zero.
Try Adding min to your options:
var options = {
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
min: 0
}
}]
}
};
Live Copepen: Chart.js Start at zero
Replaced by:
const options = {
scales: {
y: {
beginAtZero: true
}
}
};
It worked!
const options = {
scales: {
x: {
beginAtZero: true,
},
y: {
beginAtZero: true,
}
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With