From 8092340d2a4bfcd917131ba6ac5f0782a3a09fa4 Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Mon, 15 Dec 2025 16:54:47 +0200 Subject: [PATCH] Fix min max issues in statistics chart (#28493) --- src/components/chart/statistics-chart.ts | 28 ++++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/components/chart/statistics-chart.ts b/src/components/chart/statistics-chart.ts index d0bb85671e..a536e26e78 100644 --- a/src/components/chart/statistics-chart.ts +++ b/src/components/chart/statistics-chart.ts @@ -184,17 +184,11 @@ export class StatisticsChart extends LitElement { } private _datasetHidden(ev: CustomEvent) { - if (!this._legendData) { - return; - } this._hiddenStats.add(ev.detail.id); this.requestUpdate("_hiddenStats"); } private _datasetUnhidden(ev: CustomEvent) { - if (!this._legendData) { - return; - } this._hiddenStats.delete(ev.detail.id); this.requestUpdate("_hiddenStats"); } @@ -521,7 +515,9 @@ export class StatisticsChart extends LitElement { `ui.components.statistics_charts.statistic_types.${type}` ), symbol: "none", - sampling: "minmax", + // minmax sampling operates independently per series, breaking stacking alignment + // https://github.com/apache/echarts/issues/11879 + sampling: band && drawBands ? "lttb" : "minmax", animationDurationUpdate: 0, lineStyle: { width: 1.5, @@ -539,10 +535,17 @@ export class StatisticsChart extends LitElement { if (band && this.chartType === "line") { series.stack = `band-${statistic_id}`; series.stackStrategy = "all"; - if (drawBands && type === bandTop) { - (series as LineSeriesOption).areaStyle = { - color: color + "3F", - }; + if (this._hiddenStats.has(`${statistic_id}-${bandBottom}`)) { + // changing the stackOrder forces echarts to render the stacked series that are not hidden #28472 + series.stackOrder = "seriesDesc"; + (series as LineSeriesOption).areaStyle = undefined; + } else { + series.stackOrder = "seriesAsc"; + if (drawBands && type === bandTop) { + (series as LineSeriesOption).areaStyle = { + color: color + "3F", + }; + } } } if (!this.hideLegend) { @@ -586,7 +589,8 @@ export class StatisticsChart extends LitElement { } else if ( type === bandTop && this.chartType === "line" && - drawBands + drawBands && + !this._hiddenStats.has(`${statistic_id}-${bandBottom}`) ) { const top = stat[bandTop] || 0; val.push(Math.abs(top - (stat[bandBottom] || 0)));