[Chartjs]-ChartJS x-axis show only months of year

9👍

Use the time-type in your x-axis. With time: { unit: 'month' } (always months) or minUnit (months and years if necessary) you can get the month labels.

As label for your data you need to pass a Date or moment

scales: {
  xAxes: [{
    type: 'time',
    time: {
      unit: 'month'
    }
  }],
}

Here is a complete example.
Check the moment docs for dates, especially the creation and parsing of dates. Chart.js works with moment dates so it’s quite important (and quite easy btw).

Leave a comment