I am using highcharts in my angular application. Even though my charts are rendering on load, i am still getting highcharts #error-13 in my console.
I am calling my render chart method inside ngOnInit lifecycle hook. I also added the check to verify that the method should only be called once the data is available.
My html:
<div [attr.id]="chartContainerID" class="chart-container mt-0"></div>
My ts file:
export class MyComponent implements OnInit, {
chartContainerId: string;
constructor(private xrangechart: XrangeChartService, ) {
if (!this.chartContainerId) {
this.chartContainerId = String(Math.random());
}}
ngOnInit() {
// to do call the service here.
this.getData();
}
renderChart(chartOptions: any) {
const chart = this.xrangechart.renderChart(this.chartContainerId, chartOptions);
if (chart) {
this.plotShapes(chart);
}
}
getData() {
this.dataservice.subscribe(data => {
if (data !== null && data !== undefined &) {
console.log(data);
this.dataReturned = data;
this.renderChart(this.setChartOptions());
}
});
}
setChartOptions() {
const chartOptions: any = {};
// Setting chart height
chartOptions.height = 300;
// Setting the click event on the label
chartOptions.data = this.dataReturned.data;
// to set the yaxis
chartOptions.yAxis = {
gridLineWidth: chartContainer.gridLineWidth,
margin: 0,
title: {
text: ''
},
categories: this.data.categories,
reversed: true
};
return chartOptions;
}
plotShapes(chart: any) {
// some logic to plot shape
}
}
expected: The error in the console should not be present and the charts should be rendered without any error