Chartjs-Chart.js time object labels not updating correctly

0đź‘Ť

âś…

After looking at the docs and a couple forums I have found a solution that works. Chartsjs with the time config will try and guess the right time unit and when updating the chart dynamically it looks like it keeps the previous “guess”.

Passing through the actual time unit I wanted i.e by day now allows the chart to update just once per day rather than trying to push single days over multiple ticks. here’s the config example.

options: {
            responsive: true,
            maintainAspectRatio: false,
            scales: {
                xAxes: [{
                    type: 'time',
                    time: {
                        unit: 'day',
                        displayFormats: {
                            //'millisecond': 'MMM DD',
                            'second': 'MMM DD',
                           'minute': 'MMM DD',
                            'hour': 'MMM DD',
                            'day': 'MMM DD',
                            'week': 'MMM DD',
                            'month': 'MMM DD',
                            'quarter': 'MMM DD',
                            'year': 'MMM DD'
                        }
                    }
                }]
            }
        }

The difference is the unit option under time.

Leave a comment