I am using line chart from http://www.chartjs.org/
As you can see max value (1
> Best Solution
"options":{
scales: {
yAxes: [{
display: true,
ticks: {
suggestedMin: 0, //min
suggestedMax: 100 //max
}
}]
}
}
There's so many conflicting answers to this, most of which had no effect for me.
I was finally able to set (or retrieve current) X-axis minimum & maximum displayed values with chart.options.scales.xAxes[0].ticks.min
(even if min & max are only a subset of the data assigned to the chart.)
Using a time scale in my case, I used:
chart.options.scales.xAxes[0].ticks.min = 1590969600000; //Jun 1, 2020
chart.options.scales.xAxes[0].ticks.max = 1593561600000; //Jul 1, 2020
chart.update();
(I found no need to set the step values or beginAtZero
, etc.)
Since none of the suggestions above helped me with charts.js 2.1.4, I solved it by adding the value 0 to my data set array (but no extra label):
statsData.push(0);
[...]
var myChart = new Chart(ctx, {
type: 'horizontalBar',
data: {
datasets: [{
data: statsData,
[...]
The above answers didn't work for me. Possibly the option names were changed since '11, but the following did the trick for me:
ChartJsProvider.setOptions
scaleBeginAtZero: true
Chart have a "min" and "max" value. Documentation on this link
https://www.chartjs.org/docs/latest/axes/cartesian/linear.html
yAxes: [{
display: true,
ticks: {
beginAtZero: true,
steps:10,
stepValue:5,
max:100
}
}]