Chartjs-How can i put a chart in a div with *ngIf

1👍

when ngOnInit() is called there is no canvas element in the DOM since *ngIf condition is false by default.
What you need – move ChartJS initialization logic to another place (you can use another life hook method like ngAfterViewChecked to check if canvas element is rendered or not, or call this logic by user event) and only after that initialize ChartJS

as alternative, you can replace *ngIf with [class.hidden]="!showAna". Do not forget add .hidden { display: none } to css file

Leave a comment