I'm pulling data from an Angular service and trying to populate and ngx bar chart.
export class CustomersComponent implements OnInit {
customers: Customer[];
single: any = [
{
"name": [],
"value": []
}
];
view: any[] = [700, 400];
// options for the chart
showXAxis = true;
showYAxis = true;
.......
I'm looping through the data to get individual results and then passing them to chart.
ngOnInit(): void {
this.getCustomers();
this.customerService.getCustomers().subscribe(res => res.forEach((item, i , res) => {this.single.push({name:(item.firstname), value: (item.age) }) }));
this.single = [...this.single];
console.log(this.single),
(err) => {console.log(err)};
}
I can see the data in the console, but it doesn't populate the chart. I've also noticed my first object is empty and the next ones have populated.
Could this be why the chart isn't populating with data? Any help is greatly appreciated.