Vasudeva Rao Aravind
Vasudeva Rao Aravind

Reputation: 195

Setting min and max values chart.js

For a graph I am making with Chart.js, I am trying to set the max. and min values for the X-axis. As you can see from the code below, I am able to easily set these values for the Y-axis, but setting the limits for X is giving me trouble. Please help.

Please view the CodePen here: Chart.js JS code to draw a graph

myLineChart.options.scales.yAxes[0].ticks.max=20;
myLineChart.options.scales.xAxes[0].ticks.max=20;
myLineChart.update();

Upvotes: 1

Views: 1826

Answers (1)

danday74
danday74

Reputation: 56936

It is because you only have 7 labels on the x axis.

If you add more like so by changing labels from:

labels: [1,2,3,4,5,6,7],

to:

labels: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]

It works fine.

Remember you are asking for a max of 20 but there are only 7 so it can only display 7.

Upvotes: 1

Related Questions