I have been struggling to make a chart.js line chart start at 0 when all of the values are 0. If all of the data of a dataset is 0 the y axis will always show values below 0 which I don’t want there.
Here is the example:
<canvas id="lineChart"></canvas>
<script>
var ctx = document.getElementById('lineChart');
var lineChart = new Chart(ctx, {
type: 'line',
data: {
labels: [1,2,3],
datasets: [{
data: [0, 0, 0]
}]
},
options: {
responsive: true,
scales: {
y: {
ticks: {
beginAtZero:true
}
}
}
}
});
</script>
<div>```
As you can see I am changing in the options the scales as suggested in the documentation [here][1] (apparently there has been a migration and this is the way to go in v3, which is what I am using). But the graph still won't start at 0:
[![chart example][2]][2]
Any axis options other than the ticks work correctly. I have also tried
Any ideas of what I might be doing wrong?
[1]: https://www.chartjs.org/docs/master/getting-started/v3-migration.html#scales
[2]: https://i.stack.imgur.com/9IWmc.png