Skip to content
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

[Feature] How to get the axis range when datazoom scales it? #17919

Closed
masq6r opened this issue Nov 15, 2022 · 7 comments
Closed

[Feature] How to get the axis range when datazoom scales it? #17919

masq6r opened this issue Nov 15, 2022 · 7 comments
Labels
en This issue is in English support

Comments

@masq6r
Copy link

masq6r commented Nov 15, 2022

What problem does this feature solve?

Hopefully the axis range could be known when it's changed.
I have y-axis scale set to true, and enabled datazoom. When I zoom or pan the chart, clearly the y-axis's range changes too. Now I need to know the new range.
I tried to listen to datazoom event but it doesn't look like any properties in the option could give me the values.

chart.on("datazoom", params => console.log(chart.getOption().yAxis[0]))

From the output I cannot see any information showing the y-axis range. Is there a way I can get it?

What does the proposed API look like?

Add a range property in the yAxis option:

yAxis: {
    range: [currentMin: number, currentMax: number]
}
@echarts-bot echarts-bot bot added en This issue is in English pending We are not sure about whether this is a bug/new feature. labels Nov 15, 2022
@plainheart
Copy link
Member

Maybe related to #17278

@masq6r
Copy link
Author

masq6r commented Nov 15, 2022

Maybe related to #17278

Not really. I believe that the PR you quoted is about to access the data window's start-end index. In my case when I move the chart, x-axis range is changing and y-axis range is scaling to reflect that change, I'd like to know what that scaled y-axis range is.

@plainheart
Copy link
Member

All right. I'm sorry I misunderstood. For now, we can only get it like this, which is not a public method.

const yAxisExtent = myChart
    .getModel()
    // get the first y-axis
    .getComponent('yAxis', 0)
    // get scale
    .axis.scale.getExtent();

See also this demo.

@masq6r
Copy link
Author

masq6r commented Nov 16, 2022

All right. I'm sorry I misunderstood. For now, we can only get it like this, which is not a public method.

Thank you for your demo and the solution works. But since it's not public I cannot expect stability in future releases, can I? Anyway I'm closing the issue at the moment.

@masq6r masq6r closed this as completed Nov 16, 2022
@plainheart
Copy link
Member

But since it's not public I cannot expect stability in future releases, can I?

It's generally okay to use this non-public API. It's just not ready to expose to the users.

@plainheart plainheart added support and removed new-feature pending We are not sure about whether this is a bug/new feature. labels Nov 16, 2022
@bbcfive
Copy link

bbcfive commented Nov 26, 2022

hi @plainheart, but how can I solve the ts error?

Property 'getModel' is private and only accessible within class 'ECharts'.ts(2341)

@plainheart
Copy link
Member

@bbcfive This API is not exposed, so you have to use as any or // @ts-ignore to disable the TS check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
en This issue is in English support
Projects
None yet
Development

No branches or pull requests

3 participants