I have a problem with an update series data in column chart. At the beginning, when my model is empty I set an empty array as the series and then in ngOnchanges method I map my modelData to matching format. Unfortunately, the chart is still empty.
Here is my component code:
export class ColumnChartComponent implements OnInit, OnChanges {
highcharts = Highcharts;
chartConstructor: string;
@Input() dataModel: MyChartModel[];
ngOnInit(): void {
this.initChart();
}
ngOnChanges(): void {
this.chartOptions = {
series: this.getData()
};
}
private initChart(): void {
this.highcharts = Highcharts;
this.chartConstructor = "chart";
this.chartOptions = {
chart: {
type: "column"
}
//...
// others settings
//...
series: []
};
}
getData(){
// some methods to map from dataModel to expected array
// finally return something like this:
return [{
data: [2134000, 3168818, 2569759],
name: 2015,
type: "column"`enter code here`
},{
data: [2497680, 3195299, 2480444],
name: 2014,
type: "column"
},{
data: [2872000, 3604271, 2925828],
name: 2016,
type: "column"
}]
}
And finally chart is empty. What's interesting, when I set series: [{}] in initChart() method, chart show one series. If I set series: [{},{}] chart will show two series, etc. But I don't know how many series will be in my dataModel, so I cannot set the array with a suitable count of objects in the array.
I have tried use this.chartOptions.series.push(myObject) but it doesn't work too.