Chartjs-Mapping issue on Chart Js Bar Chart

0👍

You should define the x-axis as a time cartesian axis and provide the data as individual points, an array of objects, having a x (alternatively also t) and an y property each.

There’s no need for complex data processing using for loops. The response can instead be converted and directly assigned to the data properties through the Array.map() method as follows.

var chartdata = {
  // omit labels 
  datasets: [{
    ...
    data: response.call_data.map(v => ({ x: v.dated, y: v.calls })) 
  },
  {
    ...
    data: response.bill_data.map(v => ({ x: v.b_dated, y: v.b_calls })) 
  }]
};

For further information, please take a look at this answer.

The different date/time formats from the mentioned answer obviously need to be adapted to the format of your data and the desired display.

Leave a comment