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

Price Scale AutoScale does not work for small values #1495

Open
Ripwords opened this issue Jan 17, 2024 · 3 comments
Open

Price Scale AutoScale does not work for small values #1495

Ripwords opened this issue Jan 17, 2024 · 3 comments
Labels
needs investigation Needs further investigation.

Comments

@Ripwords
Copy link

Lightweight Charts™ Version:

Steps/code to reproduce:

Actual behavior:
I have a chart that is clickable (through the legends below to toggle visibility), with autoScale it has always worked as intended.

  1. Before hiding
    image

  2. After hiding, price scale is automatically scaled as intended
    image

HOWEVER, when a dataset with extremely small values (in this case 0.03333..) after hiding a chart with a larger set of values, the autoScale of price scale does nothing.

Example 1:

  1. Before hiding
    image

  2. After hiding
    image

Example 2:

  1. Before hiding
    image

  2. After hiding
    image

And since the localization is triggered here, I have also tried to disable it, and got the same results.

Expected behavior:
Expected Example 1:
image

Expected Example 2:
image

Screenshots:

CodeSandbox/JSFiddle/etc link:

@Ripwords
Copy link
Author

Based on this, could it be that the "visible data range" has a threshold? And if my dataset has values that are lower than that threshold, is there anyway i can change it?

image

@Ripwords
Copy link
Author

However, when there's only a single chart which is the dataset with the small value, the chart is showing as normal
image

@SlicedSilver SlicedSilver added the needs investigation Needs further investigation. label Jan 17, 2024
@Ripwords
Copy link
Author

Ripwords commented Jan 18, 2024

I got it working, but the workaround was discovered by accident. I'm not sure why it works.

To reproduce, first I've set both left and right price scales to visible when creating the chart instance

leftPriceScale: {
  autoScale: true,
  visible: true,
},
rightPriceScale: {
  autoScale: true,
  visible: true,
}

After which i add however many line series that i need to, all with the priceScaleId: 'left'

const lineSeries = chart.addLineSeries({
  color: Object.values(colorList)[index] as string,
  lastValueVisible: false,
  priceLineVisible: false,
  lineWidth: 2,
  priceScaleId: "left",
})

Then at the end i remove the right price scale, now the price scales auto recalculates and scales everything appropriately

chart.applyOptions({ rightPriceScale: { visible: false } })
chart.timeScale().fitContent()

The issue is solved, but i still think this isn't the intended behaviour, or maybe I'm misunderstanding something

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs investigation Needs further investigation.
Projects
None yet
Development

No branches or pull requests

2 participants