score:1

Accepted answer

it should work as expected if you make the entry inside displayformats the same as unit.

displayformats: {
  month: 'mm/yy'
}

please take a look at below runnable code and see how it works.

const now = new date();
const data = new array(100).fill().map((v, i) => {
  const date = new date();
  date.setdate(now.getdate() + i);
  return { x: date.toisostring().substring(0, 10), y: math.floor(math.random() * 10) };
});

new chart('chart', {
  type: 'line',
  data: {
    datasets: [{
        label: "data",        
        bordercolor: "rgb(255, 0, 0)",
        data: data,
        fill: false
      }
    ]
  },
  options: {
    scales: {
      yaxes: [{
        ticks: {
          beginatzero: true
        }
      }],
      xaxes: [{
        type: 'time',
        time: {
          parser: 'yyyy-mm-dd',
          unit: 'month',
          displayformats: {
             month: 'mm/yy'
          },
          tooltipformat: 'dd/mm/yy'
        }
      }]
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.9.4/chart.bundle.js"></script> 
<canvas id="chart" height="90"></canvas>


Related Query

More Query from same tag