I have a requirement to display two datasets as dual column charts.
(2) [{…}, {…}]
0:
historyDate: "2021-02-10T10:00:000Z"
documentStatusHistory:
CANCELLED: 6
COMPLETED: 52
IN_PROGRESS: 1
OPEN: 1
PHASE_OUT: 1
1:
historyDate: "2021-02-17T10:00:000Z"
documentStatusHistory:
CANCELLED: 6
COMPLETED: 52
IN_PROGRESS: 1
OPEN: 1
PHASE_OUT: 1
The chart setup is executed in the ngAfterContentInit method
ngAfterContentInit() {
const chartOptions: Options = this.createDefaultColumnOptions();
chartOptions.title.text = this.chartTitle;
this.resultChart = Highcharts.chart(this.resultChartTarget.nativeElement, chartOptions);
this.resultChart.addSeries(this.buildColumnSeries(this.uuidService.getNewUuid(), this.chartData));
}
The data for the columns is populated here
private buildColumnSeries(id: string, chartData: any[]) {
const options: SeriesOptions = {
id,
type: 'column',
data: [],
} as SeriesOptions;
chartData.forEach((item) => {
const date = new Date(item.historyDate);
const newDate = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate());
for (const status in item.documentStatusHistory) {
this.resultChart.addSeries({
type: 'column',
yAxis: 0,
name: status.replace('_', ' '),
data: [[newDate, item.documentStatusHistory[status]]],
color: DisplayUtil.getStatusColor(status)
});
}
});
return options;
}
This section handles the configuration of the chart
private createDefaultColumnOptions(): Options {
return {
chart: {
zoomType: 'xy',
marginLeft: 70,
marginRight: 70
},
title: {
useHTML: true
},
legend: {
verticalAlign: 'top',
labelFormat: '<b>{name}</b>',
enabled: true
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
week: '%e. %b'
},
title: {
text: 'Date'
}
},
yAxis: [
{ // Primary yAxis
title: {
text: 'Total ' + this.chartTitle
}
}
],
tooltip: {
shared: true
},
plotOptions: {
column: {
stacking: 'normal'
},
series: {
cursor: 'pointer'
}
},
credits: {
enabled: false
}
} as Options;
}
}
The end result should be a chart like https://i.stack.imgur.com/DUFyL.png
There seems to be an issue with duplicate legends appearing on my chart. The columns are correctly structured, but I am unsure why the legend duplicates. Any insights into what might be causing this issue?