I am using the ng2-chart library and I want to pass information from a parent component to the child component. The information is obtained from an API that provides me with the data. But it is not loading the information:
export class PruebasComponent implements OnInit {
lineChartData: ChartDataSets[];
lineChartLabels: Label[];
In ngOnInit
it I get the date
ngOnInit() {
this.loading = true;
this.datos.getDesktopLimit().subscribe(
res => {
this.loading = false;
this.data = [res];
this.dataSource = this.data[0];
this.barChartData = true;
this.getFilter(this.dataSource);
}
)
}
and through the function I am able getFilter()
to modify the data that I want to send:
getFilter(data) {
data.sort((a, b) => a.id - b.id);
for (let entry of data) {
this.date.push(moment(entry.created).format('DD-MM-YYYY HH:mm'))
this.time.push(entry.total_load_time * 0.001)
}
this.lineChartData = [{ data: this.time, label: 'Time Render' }] /* [ { data: [65, 59, 80, 81, 56, 55, 40], label: 'Series A' }] */;
this.lineChartLabels = this.date;
this.loading = false
}
[datasets]
the empty data is sent
<app-graphic [datasets]="[lineChartData]" [labels]="lineChartLabels"></app-graphic>
Try to load your component until the data has been loaded into your variable, as I see you use the "loading" variable