Issue
I created a pieChart with amCharts but I got this error html container 'chartdiv' not found
Here is file parent component
<div class="col-12 mt-4">
<app-gender-age-range-chart ></app-gender-age-range-chart>
</div>
and here is the component for the chart
<div id="{{chartId}}"></div>
In the component.ts, i declared @Input()
@Input()
chartId: string;
chartRender() {
// chart code
}
chartRender()
is placed in ngAfterViewInit()
Thank for your help!
Solution
Have you tried setting a viewChild of the element to ensure it is initialised, e.g:
Copied from JediManJS at https://github.com/amcharts/amcharts4/issues/1324
Hello. I got the same issue and found more elegant, than setTimeout function, way. In the template, I added templateVariable to div:
<div id="bar-lines-chart" style="width: 100%; height: 200px" #chartElement></div>
In the component, I made next:
@ViewChild('chartElement') chartElement: ElementRef<HTMLElement>;
and in am4core.create function:
const chart = am4core.create(this.chartElement.nativeElement, am4charts.XYChart);
Working well.
Answered By - AleksW
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.