Chartjs-Draw a Chart.js with data retrieved through ajax call

4👍

I remember having a lot of trouble to find a nice way to do it, I ended up doing it like this and then just assigning the ‘labels’ and ‘data’ array to the according properties in the data variable for the chart.

var output = [{'description': 'team1','number': 11},{'description':'team2','number': 408}, {'description': 'team3','number': 12}];

var labels = [];
var data = [];

output.forEach(function(entry) {
  labels.push(entry.description);
  data.push(entry.number);
});

https://jsfiddle.net/bn32gh94/2/

Let me know if there’s something wrong with the fiddle because it’s literally the first one I make public. 🙂

Leave a comment