[Chartjs]-How to change X-axis interval in chart.js

1๐Ÿ‘

โœ…

I think You are using data string as the label so any built-in logic is not going to work.

You can create labels dynamically based on the selected date range and interval.

var labels = [];
// get interval
var interval  = 5;
//Get start date
var date_start =  new Date("July 5");
for ( var i = 0; i <= 30; i += interval) {
    //Set date
    date_start.setDate(date_start.getDate() + interval);
    //get Month
    var month_name  = date_start.toLocaleString(navigator.language, { month: "short" });
    //Add to labels
    labels.push(month_name + " " + date_start.getDate());
}

Leave a comment