Topic: How to update line chart
Dawid Adach pro answered 7 years ago
ngOnInit() { setTimeout(() => { this.chartLabels= ['May', 'May', 'May', 'May', 'May', 'Jun', 'Jul']; console.log("dokonalo sie"); }, 5000);And the chart is getting recreated correctly.
andrews88l pro answered 7 years ago
I've had the same issue. I believe it stems from the ng-mdb-pro/typoescripts/free/charts/chart.directive.ts file in the ngOnChanges() method.
Start your code here
public ngOnChanges(changes: SimpleChanges): void {
if (this.initFlag) {
// Check if the changes are in the data or datasets
if (changes.hasOwnProperty('data') || changes.hasOwnProperty('datasets')) {
if (changes['data']) {
this.updateChartData(changes['data'].currentValue);
} else {
this.updateChartData(changes['datasets'].currentValue);
}
this.chart.update();
} else {
// otherwise rebuild the chart
this.refresh();
}
}
}
For some reason, I can't get it to trigger this.refresh(). This means we're stuck updating the current chart vs. redrawing the whole thing with the changed x-axis items. Super frustrating, especially because the y-axis adjusts dynamically.
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- User: Pro
- Premium support: No
- Technology: MDB Angular
- MDB Version: -
- Device: -
- Browser: -
- OS: -
- Provided sample code: No
- Provided link: No