Topic: Angular line graph updating data
wibar pro asked 6 years ago
Start your code here private updateChartData(newDataValues: number[] | any[]): void { if (Array.isArray(newDataValues[0].data)) { this.chart.data.datasets.forEach((dataset: any, i: number) => { dataset.data = newDataValues[i].data;if (newDataValues[i].label) { dataset.label = newDataValues[i].label; } }); } else { this.chart.data.datasets[0].data = newDataValues; } }What am i doing wrong?
Damian Gemza staff answered 6 years ago
ngAfterViewInit() { setTimeout(() => { this.chartDatasets= [ { data: [12, 12, 12, 12, 126, 12, 12], label: 'Second' }, { data: [], label: '' }, ]; }, 3000); }
wibar pro commented 6 years ago
Thx for the quick answer. From your answer it sounds like you cannot change the number of dataset, which is what i was trying to do, is this understood correctly? But it is possible to replace on of the datasets with a empty one, right? Regards, MajaDamian Gemza staff commented 6 years ago
Yes, exactly. If you need to remove some datasets, you have to set it as empty one. Best Regards, DamianFREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Resolved
- ForumUser: Pro
- Premium support: No
- Technology: MDB Angular
- MDB Version: -
- Device: -
- Browser: -
- OS: -
- Provided sample code: Yes
- Provided link: No