Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chart.js timescale: set min and max on xAxes

How can I set a min and max on the xAxes? It works fine on the yAxes but on the xAxes it shows no behavior.

My xAxes is using the type: 'time'. My labels for the xAxis are using the moment object aswell. But it also does not work when I remove the type time and use normal digits. I am using the Chart.js version 2.2.2.

scales: {
   yAxes: [{
      ticks: {
         beginAtZero:false,
      }
   }],
   xAxes: [{
      type: 'time',
      ticks: {
         min: moment(1471174953000),
         max: moment(1473853353000)
      }   
   }]
}

Here is the chart.js Time Scale documentation.

like image 593
Steckdoserich Avatar asked Sep 16 '16 15:09

Steckdoserich


2 Answers

The properties you are looking for actually are in the time attribute :

options: {
    scales: {
        xAxes: [{
            type: "time",
            time: {
                min: 1471174953000,
                max: 1473853353000
            }
        }]
    }
}
like image 199
tektiv Avatar answered Oct 20 '22 00:10

tektiv


This was changed in 3.0

https://www.chartjs.org/docs/next/getting-started/v3-migration#options

scales.[x/y]Axes.time.max was renamed to scales[id].max
scales.[x/y]Axes.time.min was renamed to scales[id].min
like image 23
avantassel Avatar answered Oct 20 '22 00:10

avantassel