I'm working currently on a hobby-project, where I load some data from a MongoDB Database, GET the data from node.js backend into my frontend, there I manipulate my data and finally I want to show the data in my Angular frontend in a Chart.js chart.
There is the problem: I am getting the data without any problems and if I load the Chart with some mock-data everything works perfectly, but when I try to load the real data in my Chart it does not show until I resize the window or for example press f12 to inspect my website.
Thanks in advance!
Here a simplified code snipped:
allTitles = [];
allSets = [];
allColors = [];
// OnInit:
this.chart = new Chart('myChart', {
type: 'doughnut',
options: {
responsive: true,
},
data: {
labels: this.allTitles,
datasets: [
{
label: 'My First dataset',
data: this.allSets,
backgroundColor: this.allColors,
borderColor: '#000000'
}
]
}
});
// A Function to get the Data from my Service:
this.parseService.getPlans().subscribe((plans: any) => {
plans.forEach(plan => {
this.parseService.getExercisesByPlan(plan._id).subscribe((exercises: any) => {
this.neighbourSetsCounter = 0;
exercises.forEach(exercise => {
this.neighbourSetsCounter += exercise.sets;
});
this.allTitles[this.neighbourCounter] = plan.title;
this.allSets[this.neighbourCounter] = this.neighbourSetsCounter;
this.allColors[this.neighbourCounter] = plan.color;
this.neighbourCounter++;
});
});
});