score:404

Accepted answer

for chart.js 2.*, the option for the scale to begin at zero is listed under the configuration options of the linear scale. this is used for numerical data, which should most probably be the case for your y-axis. so, you need to use this:

options: {
    scales: {
        yaxes: [{
            ticks: {
                beginatzero: true
            }
        }]
    }
}

a sample line chart is also available here where the option is used for the y-axis. if your numerical data is on the x-axis, use xaxes instead of yaxes. note that an array (and plural) is used for yaxes (or xaxes), because you may as well have multiple axes.

score:4

please add this option:

//boolean - whether the scale should start at zero, or an order of magnitude down from the lowest value
scalebeginatzero : true,

(reference: chart.js)

n.b: the original solution i posted was for highcharts, if you are not using highcharts then please remove the tag to avoid confusion

score:10

if you need use it as a default configuration, just place min: 0 inside the node defaults.scale.ticks, as follows:

defaults: {
  global: {...},
  scale: {
    ...
    ticks: { min: 0 },
  }
},

reference: https://www.chartjs.org/docs/latest/axes/

score:34

it's now (5 years later and version 3.x) a bit different

options: {
        scales: {
            y: {
                beginatzero: true
            }
        }
    }

see: https://www.chartjs.org/docs/latest/#creating-a-chart


Related Query

More Query from same tag