Chartjs-Charts.js legend more than view value

1๐Ÿ‘

โœ…

I believe what you are looking for is ticks:{max:x}. Add it to your yAxes scale.

var chartInstance = new Chart(ctx, {
    type: 'line',
    data: data,
    options: {
        scales: {
            yAxes: [{
                ticks: {
                    max: 5,
                    min: 0,
                    stepSize: 0.5
                }
            }]
        }
    }
});

Edit: If you want a dynamic maximum value, you could determine the largest value of your data set, find an integer a set percentage above it, and set the maximum of the y-axis to that value.

var data = [1, 2, 3];
var newmax = Math.max(...data);
newmax = Math.round(newmax*1.2);

And then set the ticks max equal to newmax:

ticks:{max:newmax}.

Leave a comment