I have a backend api in which i created a web service that gives this json response:
[
{
"backgroundColor": "#36A2EB",
"hoverBackgroundColor": "#36A2EB",
"type": "SUCCESS",
"value": 1
}
]
this is my ts code:
data: any;
ngOnInit(): void {
this.dashboardService.getStatStatusOverall().subscribe((data)=>{
this.data.datasets[0].data = data.map(a => a.value);
this.data.datasets[0].backgroundColor = data.map(a => a.backgroundColor);
this.data.datasets[0].hoverBackgroundColor = data.map(a => a.hoverBackgroundColor);
this.data.labels = data.map(a => a.type);
//this.chart.refresh();
})
}
and this this is my html code:
<p-chart type="doughnut" [data]="data"></p-chart>
I get this error in my console:"Cannot read property 'datasets' of undefined"