Chartjs-Chartjs plot datetime value with time offset on the grid

0👍

That should be the default behaviour for the time axis, assuming it’s configured correctly. I’ve added a couple of data points to your set so as to illustrate in the snippet below.

Also, I see that you’ve tagged your question as chartjs-2.6.0. Axis handling was significantly improved in more recent releases so upgrade if you can.

new Chart(document.getElementById("chart"), {
  type: "line",
  data: {
    datasets: [{
      data: [{
          t: '2019-08-14T09:00:00Z',
          y: 0.1
        },
        {
          t: '2019-08-15T09:00:00Z',
          y: 0.3
        },
        {
          t: '2019-08-15T17:00:00Z',
          y: 0.3
        },
        {
          t: '2019-08-16T09:00:00Z',
          y: 0.5
        }
      ]
    }]
  },
  options: {
    scales: {
      xAxes: [{
        type: "time",
        time: {
          unit: "day"
        }
      }]
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.bundle.min.js"></script>
<canvas id="chart"></canvas>

Leave a comment