ChartJS: How to set fixed Y axis max and min

Nayzer picture Nayzer · Dec 19, 2016 · Viewed 26.2k times · Source

I have a line chart which I'm trying to set a fixed max and min values. I have tried the other suggestions found on SO, but it still doesn't work. My chart keeps re-setting the max and min values depending on the incoming data.

Here's my current options that I pass to my Line chart:

var options = {
        responsive: true,
        animation: false
};

I tried those settings too:

var options = {
    scales: {
        animation: false,
        yAxes: [{
            display: true,
            ticks: {
                suggestedMin: -1,
                suggestedMax: 1
            }
        }]
    }
};

Any idea what I'm doing wrong?

Thanks!

Answer

Sanjay Dutt picture Sanjay Dutt · Dec 19, 2016

To fix min and max value for yAxes scale use the below code.

options:{
            scales: {
                yAxes : [{
                    ticks : {
                        max : 1,    
                        min : -1
                    }
                }]
            }
        }

suggestedMax will only works when incoming data is lower than suggestedMax value. suggestedMin will works only when incoming data is greater than suggestedMin value.