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 newarray
populated with the results of calling the provided function on every element in thearray
.
Source:stackexchange.com