[Chartjs]-Chart.js time scale showing one of the dates wrong

1👍

I’m not sure this is a bug actually. If we expand the fiddle, we’ll see that it’s using the abbreviated dates for years, and quarters are spelled out.

Chart year formats example

However, when we shrink the chart so it appears as in your screenshot, it just so happens we see October 2013, July 2014, April 2015, and then finally we get to the beginning of January 2016, so that’s the one that looks weird.

I’m guessing that’s because of an ambiguity with January 1 being both a quarter and a year. The solution is to explicitly set the spelled-out date format for quarters and years in your chart settings:

new Chart(ctx, {
  //stuff and things
  scales: {
    xAxes: [{
      type: "time",
      time: {
        displayFormats: {
          year: 'YYYY-MM-DD',
          quarter: 'YYYY-MM-DD'
      }
      //et cetera
    }]
  }
});

Leave a comment