Chartjs-Chart.js with json data and jquery – error :-(

0👍

According to your API you are receiving this object :

{
...,

  "data":[[1586736000000,0],[1586736900000,null]...]

...,
}

when you do this :

var labels = data.chartData.data[0].map(...)

You are targeting the first array of data. Which is [1586736000000,0].

So to fix your issue you can just do it like this:

var labels = data.chartData.data.map(function(e) {
  return e[0];
});

var data = data.chartData.data.map(function(e) {
  return e[1];
});

labels will return : [1586736000000,1586736900000,...]

data will return : [0,null,...]

Also to not go through the same array twice you may prefer to use a forEach.

Leave a comment