Chartjs-ChartJS time axis not plotting correctly | getting an hour instead of date

1👍

You could define time.unit option ‘day’ on your xAxis as explained here. This will display the xAxis tick mark in the default display format defined for ‘day’.

xAxes: [{
  type: 'time',
  time: { 
    unit: 'day'     
  }
  ... 

In case you want the date to be displayed in a different format, the definition could look as follows.

xAxes: [{
  type: 'time',
  time: { 
    unit: 'day',
    displayFormats: {
      day: 'YYYY-MM-DD'
    },
    tooltipFormat: 'YYYY-MM-DD'
  }

See Moment.js for the allowable format strings.

Leave a comment