Skip to content

feat(axis): support dataMin/dataMax to calc a nice axis range #20838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Justin-ZS
Copy link

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Add dataMin and dataMax properties for value axes to extend the axis range while preserving nice scale algorithm.

Fixed issues

Details

Before: What was the problem?

Currently, ECharts provides two ways to set axis range:

  1. Let ECharts auto-calculate nice values by default
  2. Use min/max to set fixed values, but this disables the nice scale algorithm

There was no way to ensure a specific data point would be included in the axis range while still benefiting from the nice scale algorithm.

After: How does it behave after the fixing?

With the new dataMin/dataMax properties, users can:

  • Specify values that should be included in the axis range
  • Only affect the range if the specified value extends beyond the actual data range
  • Still benefit from ECharts' nice scale algorithm for rounding values

These properties are only effective for value axes (value, log) and have no effect on category axes.

Document Info

One of the following should be checked.

  • This PR doesn't relate to document changes
  • The document should be updated later
  • The document changes have been made in apache/echarts-doc#xxx

Misc

ZRender Changes

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

Related test cases or examples to use the new APIs

Test cases have been included in test/axis-data-min-max.html to verify different scenarios including:

  • Basic usage with standard value axes
  • Scenarios with negative values
  • Usage with log axes
  • Verification that they don't affect category axes

Others

Merging options

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

Other information

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

echarts-bot bot commented Mar 19, 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.

@Justin-ZS
Copy link
Author

@Ovilia @100pah Could you help to review the PR? Thanks!

@sjcobb
Copy link

sjcobb commented Apr 12, 2025

I’ve experienced this problem as a user so interested to see how this PR progresses, I will say the naming here is a bit confusing, especially since ECharts already supports a different concept as: min: 'dataMin' and max: ‘dataMax’

@Justin-ZS
Copy link
Author

I’ve experienced this problem as a user so interested to see how this PR progresses, I will say the naming here is a bit confusing, especially since ECharts already supports a different concept as: min: 'dataMin' and max: ‘dataMax’

I intentionally use the terms dataMin/dataMax:

  1. From a usage perspective, dataMin/dataMax should not be used simultaneously with min/max.
  2. If a user does combine them, dataMin/dataMax will affect the result of min: 'dataMin' and max: ‘dataMax’.
    For example: if the original data range is [100, 300], setting { dataMax: 500, max: 'dataMax' } will fix the axis maximum to 500.
    Using the same terms here makes the it more intuitive.
  3. I'm open to change the name if the maintainers have any recommendations

Copy link
Contributor

@Ovilia Ovilia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a little unexpected to me. Have you tried with the callback of axis.min?

yAxis: {
  max: value => Math.max(value, 1000)
}

or simply

yAxis: {
  max: 'dataMax'
}

@Justin-ZS
Copy link
Author

Justin-ZS commented Apr 17, 2025

This seems a little unexpected to me. Have you tried with the callback of axis.min?

yAxis: {
  max: value => Math.max(value, 1000)
}

or simply

yAxis: {
  max: 'dataMax'
}

Neither approach works in this case.
As described in #20770, we need a simple way to set the axis max to a nice round value.
This feature is particularly valuable when comparing multiple similar charts that should share the same axis range.
With this feature, I can just set the dataMax to the max value of all charts, then all charts will have the same axis range.

@Ovilia
Copy link
Contributor

Ovilia commented Apr 23, 2025

@Justin-ZS Can you further explain in which case should I set max value to be some rounded value larger than my given value, instead of not setting max at all?

@Justin-ZS
Copy link
Author

@Justin-ZS Can you further explain in which case should I set max value to be some rounded value larger than my given value, instead of not setting max at all?

When comparing multiple similar charts. (like sales data from different stores, one chart for one store)
When not setting the max, the axis max of chart 1 is 4000, and the axis max of chart 2 is 3000.
Setting "max" to all charts directly will make them ugly, as the max value could be 3744.55
With this new feature, all axis max will be 4000.

@Justin-ZS Justin-ZS requested a review from Ovilia April 23, 2025 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: awaiting doc Document changes is required for this PR. PR: awaiting review size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants