1👍
You are using async code but expecting it to work like sync code. When you call new Chart
all the arrays are still empty. So you will need to adjust the chart directly in your ajax and not the original variables or create the chart in your ajax
$.ajax({
url : "../controllers/getCategoryNames.php",
method :"GET",
success: function(data){
let categoryData = JSON.parse(data);
for(let i in categoryData){
myChartOne.data.labels.push(categoryData[i].category_name);
}
myChartOne.update();
}
})
- [Chartjs]-Chartjs stacked bar separate tooltip for all stacked
- [Chartjs]-Zoom chartjs with many X values
Source:stackexchange.com