Skip to content

fix: respect series.hidden flag on initial render by emptying collapsed series data - #5248

Open
waterWang wants to merge 1 commit into
apexcharts:mainfrom
waterWang:fix/hidden-flag-series
Open

fix: respect series.hidden flag on initial render by emptying collapsed series data#5248
waterWang wants to merge 1 commit into
apexcharts:mainfrom
waterWang:fix/hidden-flag-series

Conversation

@waterWang

Copy link
Copy Markdown
Contributor

Description

The series.hidden config option was being tracked in collapsedSeriesIndices global state via getSeriesAfterCollapsing(), but the actual series data was not being emptied before rendering. This caused hidden series to still be drawn (visible) on the chart, even though the legend labels correctly showed them as dimmed.

Root Cause

When a user sets hidden: true on a series config, the create() method in apexcharts.js iterates through the series and calls getSeriesAfterCollapsing() for each hidden series. This correctly adds the index to collapsedSeriesIndices, but the cloned series data returned by the function is still passed to parseData() with all values intact. The rendering pipeline then draws the SVG paths for those series, and while the CSS class apexcharts-series-collapsed (opacity: 0) is added, the paths are still present in the DOM.

Fix

Empty the data array for all indices tracked in collapsedSeriesIndices and ancillaryCollapsedSeriesIndices after the initial forEach loop. This follows the same pattern already used in LegendHelpers._getSeriesBasedOnCollapsedState(), which is called when a series is hidden/risen via legend interaction.

Testing

  1. Create a line chart with multiple series
  2. Set hidden: true on one or more series
  3. The hidden series should not be rendered on the chart

Fixes #5213

…ed series data

The series.hidden config option was being tracked in
collapsedSeriesIndices global state (via getSeriesAfterCollapsing),
but the actual series data was not being emptied before rendering.
This caused hidden series to still be drawn (visible) on the chart,
even though the legend labels correctly showed them as dimmed.

The fix follows the same pattern used in
LegendHelpers._getSeriesBasedOnCollapsedState, which is already
called when a series is hidden/risen via legend interaction: empty
the data array for all indices tracked in collapsedSeriesIndices
and ancillaryCollapsedSeriesIndices.

Fixes apexcharts#5213
@junedchhipa

Copy link
Copy Markdown
Contributor

Thanks for the PR!

I tried to reproduce this on current main (6.7.0) and I can't get the bug to trigger. With hidden: true set on one or more series at init, the hidden series already get the apexcharts-series-collapsed class, their data is already emptied, and no line/area/bar path is drawn.

The reason is that create()'s existing hidden-flag loop calls getSeriesAfterCollapsing(), which ends in _getSeriesBasedOnCollapsedState() and empties data for exactly the same collapsed/ancillary indices this PR targets. I applied your patch and the render output is byte-identical to main across every case I tried (single hidden, half-hidden, bar, showAlways yaxis, and legend-collapse followed by updateOptions). So the added block re-empties already-empty arrays.

I think #5213 (reported on 5.10.4) was fixed by other work since then.

  1. Could you share a reproduction pinned to the latest version? The linked sandbox looks like it predates the fix.
  2. One concern with the current approach: create() runs as create(this.w.config.series, …), so when no series has a hidden flag, series === w.config.series and s.data = [] mutates the user's config in place (the existing path deliberately works on a Utils.clone).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"hidden" flag on series does not hide the series on render

2 participants