Skip to content

Conversation

Justin-ZS
Copy link
Contributor

@Justin-ZS Justin-ZS commented May 27, 2025

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Add support for reversing stack order in stacked charts through a new stackOrder option.

Fixed issues

#20983

Details

Before: What was the problem?

Previously, stacked charts (bar, line, area) only supported the default stacking order where series are stacked in the order they are defined.
Users had no way to reverse the visual stacking order without manually reordering their series data, which could be inconvenient.

After: How does it behave after the fixing?

Now users can set stackOrder: 'seriesDesc' on any series in a stack group to reverse the visual stacking order. The feature works by:

  1. Adding a new stackOrder option to SeriesStackOptionMixin with values 'seriesAsc' (default) or 'seriesDesc'
  2. Modifying the data stack processor to check for the stackOrder setting and reverse the stack info list when needed
  3. Properly updating the stackedOnSeries calculation to maintain correct stacking relationships

The feature supports all chart types that use stacking (bar, line, area charts).
Note that polar coordinate systems are not yet supported, and documentation will be updated accordingly.
Future enhancements may include value-based ascending/descending stack ordering.

Document Info

One of the following should be checked.

Misc

ZRender Changes

  • This PR depends on ZRender changes (ecomfe/zrender#xxx).

Related test cases or examples to use the new APIs

  • test/bar-stack-reverse.html - Comprehensive test cases demonstrating the new stackOrder functionality with vertical bars, horizontal bars, and stacked line charts
截屏2025-05-27 16 18 52

Others

Merging options

  • Please squash the commits into a single one when merging.

Other information

Limitations:

  • Polar coordinate systems are not yet supported
  • Currently only supports 'seriesAsc' and 'seriesDesc' order (value-based sorting may be added in future versions)

Future Enhancements:

  • Support for polar coordinate systems
  • Potential support for value-based ascending/descending stack ordering

@echarts-bot echarts-bot bot added PR: awaiting doc Document changes is required for this PR. PR: awaiting review labels May 27, 2025
Copy link

echarts-bot bot commented May 27, 2025

Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout the coding standard and Wiki about How to make a pull request.

Document changes are required in this PR. Please also make a PR to apache/echarts-doc for document changes and update the issue id in the PR description. When the doc PR is merged, the maintainers will remove the PR: awaiting doc label.

@sjcobb
Copy link

sjcobb commented May 27, 2025

🙌 and really love the future enhancement idea for "value-based ascending/descending stack ordering"

@helgasoft
Copy link

test/bar-stack-reverse.html is a demonstration of expected results, with data order and colors predefined in data.
Would you also add an actual test case to see how the new parameter works with the official example ?
Especially regarding default colors, legend order and user switching between 'normal' and 'reverse'.

@Justin-ZS
Copy link
Contributor Author

test/bar-stack-reverse.html is a demonstration of expected results, with data order and colors predefined in data. Would you also add an actual test case to see how the new parameter works with the official example ? Especially regarding default colors, legend order and user switching between 'normal' and 'reverse'.

new test case added.

Copy link
Contributor

The changes brought by this PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-20998@dcebabd

@helgasoft
Copy link

@Justin-ZS, the latest test/bar-stack-reverse.html still has plenty of itemStyle.color defined.
To test for default colors all custom colors need to be removed.
Maybe the best test is to use the official example and just add the new parameter stackOrder:'seriesDesc' in the first series. That will also show what happens to the legend order.

@Ovilia,

PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-20998@dcebabd

Unfortunately, this convenient way of testing PRs does not seem to work anymore. If someone could fix it, that would be fantastic; if not, please disable the confusing message from the github-actions bot.

@Justin-ZS
Copy link
Contributor Author

@Justin-ZS, the latest test/bar-stack-reverse.html still has plenty of itemStyle.color defined. To test for default colors all custom colors need to be removed. Maybe the best test is to use the official example and just add the new parameter stackOrder:'seriesDesc' in the first series. That will also show what happens to the legend order.

@Ovilia,

PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-20998@dcebabd

Unfortunately, this convenient way of testing PRs does not seem to work anymore. If someone could fix it, that would be fantastic; if not, please disable the confusing message from the github-actions bot.

The Interactive Test - Based on Official Example doesn't has any custom colors.
Base on your new comments, all itemStyle in other test cases have been removed.

@Ovilia
Copy link
Contributor

Ovilia commented Jun 16, 2025

@helgasoft Thanks for reporting. The service we're using for the bot is going to shut down. I should look for another one when I have time. Currently working towards v6 is the highest priority.

@Ovilia Ovilia merged commit 79f123b into apache:master Jun 16, 2025
0 of 2 checks passed
@Ovilia Ovilia added this to the 6.0.0 milestone Jun 16, 2025
@Ovilia Ovilia added PR: doc ready and removed PR: awaiting doc Document changes is required for this PR. labels Jun 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants