Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set max and min value for Y axis

Tags:

chart.js

I am using line chart from http://www.chartjs.org/ enter image description here

As you can see max value (130) and min value (60) for Y axis are chosen automatically , I want max value = 500 and min value=0. Is this possible?

like image 425
Rajendra Thorat Avatar asked Oct 17 '22 06:10

Rajendra Thorat


People also ask

How do you change the maximum value on a chart?

In the Format Axis dialog box, click Scale, and under Value axis scale, modify any of the following options: To change the number at which the vertical (value) axis starts or ends, for the Minimum or Maximum option, type a different number in the Minimum box or the Maximum box.


1 Answers

For chart.js V2 (beta), use:

var options = {
    scales: {
        yAxes: [{
            display: true,
            ticks: {
                suggestedMin: 0,    // minimum will be 0, unless there is a lower value.
                // OR //
                beginAtZero: true   // minimum value will be 0.
            }
        }]
    }
};

See chart.js documentation on linear axes configuration for more details.

like image 335
Ofer Segev Avatar answered Oct 18 '22 19:10

Ofer Segev