I am trying to remove data (yAxis/series) from the charts, but i can not understand why my code is not work correctly. I am sending Observable data from the parent to the child component with chart. I have 2 codes which works or not. In my opinion there is a problem with synchronization forEach loop with remove(true).
I mean. When i am using forEach() or for() loop and I try to remove yAxis then some iterations of loop are missed and the chart does not remove all data.
In the other hand if i use setTimeout() with remove(true), the problem is solved and everything is deleting. Any Idea what is the problem?
Workable code:
this.chart.series.forEach((serie: Highcharts.Series) => {
if (!this._series.has(serie.options.id)) {
const yAxis = this.chart.get(serie.options.id) as Highcharts.Axis;
if (yAxis) {
setTimeout(() => {
yAxis.remove(true);
});
}
}
});
Broken code:
this.chart.series.forEach((serie: Highcharts.Series) => {
if (!this._series.has(serie.options.id)) {
const yAxis = this.chart.get(serie.options.id) as Highcharts.Axis;
if (yAxis) {
yAxis.remove(true);
}
}
});
The first one is working correctly. I am looking for the answer why iterations of loop are missing when i do not use setTimeout(). Is there a problem with synchronization?
Thanks for the answers.