tradingview / lightweight-charts

Performant financial charts built with HTML5 canvas
https://www.tradingview.com/lightweight-charts/
Apache License 2.0
9.49k stars 1.63k forks source link

Price axis width calculated based on displayed label. #1626

Open xuzhaobin opened 4 months ago

xuzhaobin commented 4 months ago

image image When the chart is small, the blank space on the left is too large. I didn't activate lastPrice, so theoretically, all I need is calculate the width based on the displayed label.

SlicedSilver commented 4 months ago

The price scale width is leaving extra space because it know how much space it would require to display a non-zero label. When the user scrolls, zooms, or new data is added then it is possible that the price scale range will change. In this case it would appear buggy if the width of the price scale was always changing.

If you only need to display the zero line on the chart then you could use a custom formatter and have it output a shorter label based on the input numbers.

The option you need to adjust depends on your case. You would probably want to adjust the percentageFormatter on the chart options.

xuzhaobin commented 4 months ago

Even if I use PriceFormatterFn, this method will give me some data that is not displayed on the price axis, and I have no way to judge which ones are displayed on the price axis, so I will format them normally. image image image

jabeztadesse commented 2 months ago

Working solution here?