Flat data structure
You can separate the metadata from your diagrams (name, identifier, etc.) from the actual data points that will change and animate.
The *ngFor will use an array of metadata, and each chart component will have @Input() , which will be retrieved from a separate data point object.
// Metadata this.charts = [ { id: 1, title: 'Chart Title 1', }, { id: 2, title: 'Chart Title 2', } ]; // Data Points this.chartData = { 1: [87, 95, 121, 20, 60, 131, 10, 139, 128, 99], 2: [56, 107, 107, 144, 43, 7, 67, 35, 141, 62] }
Template
<div *ngFor="let chart of charts"> <app-chart [inputMeta]="chart" [inputData]="chartData[chart.id]"></app-chart> </div>
Then, in the chart component, you can use the ngOnChanges() life cycle binding to update the chart when updating your data points.
adriancarriger
source share