Chartjs-Live updating chart with data from database with Chart.js

1👍

Following the suggestion, Tushar made in his comment, the success function could be changed as follows:

success: function(data) {
  dataChart.data.labels = data.map(v => v.question);
  dataChart.data.datasets[0].data = data.map(v => v.vote_count);
  dataChart.update();
},

This solution uses the Array.map() method that creates a new array populated with the results of calling the provided function on every element in the array.

Leave a comment