lightweight-charts icon indicating copy to clipboard operation
lightweight-charts copied to clipboard

Option to limit price scale range

Open clark800 opened this issue 1 year ago • 4 comments

I have a a set of baseline series that are always positive and I'd like to be able to zoom in on a narrow price range but don't want to allow the price scale to get into negative territory.

The ideal solution would be to have minimum and maximum options on the price scale that act like fixLeftEdge and fixRightEdge except that they are specified with a constant value instead of being based on the range of the data.

clark800 avatar Jul 15 '23 21:07 clark800

When the chart is automatically adjusting the price scale min and max range values, this is called autoScale and what it is doing is automatically adjusting the scale to ensure that all the data fits within the chart.

You can disable autoScale on the Price scale with: https://tradingview.github.io/lightweight-charts/docs/api/interfaces/PriceScaleOptions#autoscale

You could also use the autoscaleInfoProvider option (which can be applied to any series via the series options) which allows to you customise the scaling. So if you used autoscaleInfoProvider on all the series, and made it return the minimum and maximum values which you would prefer then you could achieve the desired effect.

  • https://tradingview.github.io/lightweight-charts/docs/api/interfaces/SeriesOptionsCommon#autoscaleinfoprovider

SlicedSilver avatar Jul 17 '23 08:07 SlicedSilver

@SlicedSilver Thanks for the idea. My feature request might not have been clear enough that the limit is about how far the user can adjust the scale (by dragging on the axis or chart area). The autoscale settings don't limit this, so I don't think it will help in this case.

clark800 avatar Jul 17 '23 16:07 clark800

You are correct. AutoScaleInfo won't help for that case. I'll mark the issue as a feature request.

SlicedSilver avatar Jul 17 '23 17:07 SlicedSilver

Solution?

jabeztadesse avatar Aug 18 '24 10:08 jabeztadesse