[Chartjs]-Add data to dynamically created Chart.js dataset

1👍

I finally figured it out. It was much easier then I thought and I have no idea why I didn’t figure this out sooner..

Simply create seperate arrays within the first $.each loop and set the values..

var trendDataset = [];

$.each(trends.keywords, function(index, keyword) {
  // Create an Array for each data object
  trendData = [];
  trendLabels = [];
    $.each(keyword.data, function(index, data) {
      trendLabels[index] = data.month,
      trendData[index] = data.popularity
    });  
  // Push the array with data to another array
  trendDataset[index].data = trendData;
});

Leave a comment