I am currently utilizing the ng2-chart library and I'm trying to pass data from a parent component to a child component. The data is retrieved from an API source. However, I am facing an issue where the information is not being loaded:
export class PruebasComponent implements OnInit {
lineChartData: ChartDataSets[];
lineChartLabels: Label[];
Within the ngOnInit
method, I'm fetching the data
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);
}
)
}
Using the getFilter()
function, I am able to manipulate the data before sending it:
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' }];
this.lineChartLabels = this.date;
this.loading = false
}
The [datasets]
attribute sends empty data
<app-graphic [datasets]="lineChartData" [labels]="lineChartLabels"></app-graphic>