diff --git a/src/core/components/chart/chart.ts b/src/core/components/chart/chart.ts index 5021bd313..dbff890ca 100644 --- a/src/core/components/chart/chart.ts +++ b/src/core/components/chart/chart.ts @@ -57,6 +57,7 @@ export class CoreChartComponent implements OnDestroy, OnInit, OnChanges { @ViewChild('canvas') canvas?: ElementRef; chart?: ChartWithLegend; + legendItems: ChartLegendLabelItem[] = []; /** * @inheritdoc @@ -105,6 +106,8 @@ export class CoreChartComponent implements OnDestroy, OnInit, OnChanges { }, options: { legend }, }); + + this.updateLegendItems(); } /** @@ -126,6 +129,8 @@ export class CoreChartComponent implements OnDestroy, OnInit, OnChanges { }; this.chart.data.labels = this.labels; this.chart.update(); + + this.updateLegendItems(); } /** @@ -179,6 +184,13 @@ export class CoreChartComponent implements OnDestroy, OnInit, OnChanges { } } + /** + * Recompute legendItems property. + */ + protected updateLegendItems(): void { + this.legendItems = (this.chart?.legend?.legendItems ?? []).filter(item => !!item); + } + } // For some reason the legend property isn't defined in TS, define it ourselves. diff --git a/src/core/components/chart/core-chart.html b/src/core/components/chart/core-chart.html index c0f03eb55..f8b0b20f4 100644 --- a/src/core/components/chart/core-chart.html +++ b/src/core/components/chart/core-chart.html @@ -1,7 +1,7 @@ - + {{data.text}}