[Chartjs]-Chart.js time scale graph – xAxis labelling

1👍

This seems to work. This code starts from today and adds in the next 10 days. You’ll have to change date to whenever you want your start date to be as well as how many dates you need.

let labels = [];
var date = new Date();
var options = {
  month: "long",
  day: "numeric"
};

for (i = 0; i < 10; i++) {
    date.setDate(date.getDate() + i);
    labels.push(date.toLocaleDateString("en-US", options));
}


var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
   type: 'line',
   data: {
      labels: labels,
      ...

Leave a comment