leeoniya / uPlot

📈 A small, fast chart for time series, lines, areas, ohlc & bars
MIT License
8.83k stars 385 forks source link

[Question] - Automatically Align Multiple y-axes #1019

Open diego-curti opened 3 weeks ago

diego-curti commented 3 weeks ago

Hi,

Is there any way to automatically align all y-axes?

Here's a simplified example to illustrate the issue:

When there is only one y-axis where the zoom level on y is adjusted manually (by the user):

Screenshot from 2024-11-07 12-49-50

If I add more series which uses other y-axes, the zero points on the y-axes no longer align:

Screenshot from 2024-11-07 12-50-01

I suspect this misalignment may happen because I re-create the chart with all series (including new ones) and then apply the previous zoom level to the initial y-axis (the one I had at first)

For context, I set the zoom with:

 u.setScale("y1", { min: minValue, max: maxValue })

I don't know if this is the proper way to add more series with other y-axis while maintaining the current zoom level on the existing series.

Note: The chart may contain several series with substantial data, so performance is a critical factor.

This is an example of what I would expect:

Note: I manage to reproduce it by manually reseting all scales, adding new series and then putting the zoom on all y-axis also manually as a final user.

Screenshot from 2024-11-07 12-50-13