I have a stackblitz here - https://stackblitz.com/edit/svg-donuts-fhnnmo?file=src%2Fapp%2Fdonuts.component.ts
I have three donut charts created with svg stroke-dasharray
The position of each segment should follow on from the previous chart segment
So the first charts segment is 60% then the second charts segment should start at 60%.
I can set the segment position using:
Circumference − All preceding segments’ total length + First segment’s offset = Current segment offset
In the ngFor loop I'm calling a updatePercent function to get the length of the previous segments and starting position.
This works for the first and last segements but not the middle one.
In the console I'm getting the error ExpressionChangedAfterItHasBeenCheckedError
and the console log seems to continue more than I was expecting.
What does ExpressionChangedAfterItHasBeenCheckedError
mean
import { Component, Input } from '@angular/core';
@Component({
selector: 'donuts',
templateUrl: './donuts.template.html'
})
export class DonutsComponent {
@Input() donutData: any;
public startOffset = 25;
public strokeDashOffset;
public firstOffset;
public previousValues = [];
updatePercent(i:number, donut:any){
if(donut){
if(i === 0){
this.firstOffset = donut.percent
this.previousValues.push(this.startOffset)
this.previousValues.push(this.firstOffset)
this.strokeDashOffset = this.startOffset
}else{
this.previousValues.push(donut.percent);
console.log(this.previousValues.reduce((a, b) => a + b, 0))
this.strokeDashOffset = 100-this.previousValues.reduce((a, b) => a + b, 0);
}
}
}
}