Q: Chart.js v2 – x-axis time scale configuration

2👍

Instancing the chart you need to put this:

var start = new Date();
start.setHours(0,0,0,0);
var end = new Date();
end.setHours(23,59,59,999)
chartLine = new Chart(chartEl, {
    ...
    options: {
        ...
        scales: {
            xAxes: [{
                type: 'time',
                time: {
                    minUnit: 'minute',
                    unit: 'minute',
                    unitStepSize: 30,
                    min: start,
                    max: end
                },
                ...
            }
            ...
        }
    }
}

Leave a comment