From 116716c51da210677e7313e4a82589d94be40c7f Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Tue, 27 May 2025 21:43:32 +0300 Subject: [PATCH] Fix duplicate legend items when comparing energy data (#25610) --- src/components/chart/ha-chart-base.ts | 40 ++++++++++++------- .../hui-energy-devices-detail-graph-card.ts | 18 +++++++++ 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/components/chart/ha-chart-base.ts b/src/components/chart/ha-chart-base.ts index 64db12b3df..2ecad752a3 100644 --- a/src/components/chart/ha-chart-base.ts +++ b/src/components/chart/ha-chart-base.ts @@ -220,11 +220,11 @@ export class HaChartBase extends LitElement { return nothing; } const datasets = ensureArray(this.data); - const items = (legend.data || - datasets + const items: LegendComponentOption["data"] = + legend.data || + ((datasets .filter((d) => (d.data as any[])?.length && (d.id || d.name)) - .map((d) => d.name ?? d.id) || - []) as string[]; + .map((d) => d.name ?? d.id) || []) as string[]); const isMobile = window.matchMedia( "all and (max-width: 450px), all and (max-height: 500px)" @@ -239,20 +239,32 @@ export class HaChartBase extends LitElement { })} >