1👍
✅
Ajax calls are asynchronous… this mean the data
will be set before getting any response from your ajax request.
In order to fix this, you need to create your data in the ajax success callback function:
$.ajax({
success: function (data) {
$.each(data, function (k, v) {
labelValues.push(v.opis);
dataValues.push(v.potroseno_tekucine);
});
var data2 = {
labels: labelValues,
//...
};
//Insert your logic here to handle data2
}
});
Source:stackexchange.com