[Chartjs]-I have 10 points inn x-axis, ranging [-25,-20,,-15,-10,0,10,20,30,40,50]. But I want my line chart to start from -15 of x-axis. How we can achieve?

0👍

Try to use min and max instead of suggestedMin and suggestedMax as follows:

xAxes: [{
  ticks: {
    min:  -15,
    max:  40
  }
}]

From Chart.js documentation

Axis Range Settings

The suggestedMax and suggestedMin settings only change the data values that are used to scale the axis. These are useful for extending the range of the axis while maintaining the auto fit behaviour.

Tick Configuration

min: User defined minimum value for the scale, overrides minimum value from data.

max: User defined maximum value for the scale, overrides maximum value from data.

UPDATE

The problem is probably that the labels are strings but min and max are defined as numbers. This can be solved in two different ways.

Either you transform the labels into numbers or you define min and max as follows:

xAxes: [{
  ticks: {
    min: '-15',
    max: '40'
  }
}]

Leave a comment