tradingview / lightweight-charts

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

priceLineSource option seems not working #1448

Closed liesauer closed 11 months ago

liesauer commented 1 year ago

Lightweight Charts™ Version: 4.1.0

Steps/code to reproduce:

chart.addCandlestickSeries({
    priceLineSource: PriceLineSource.LastBar,
    upColor: '#26a69a',
    downColor: '#ef5350',
    borderVisible: false,
    wickUpColor: '#26a69a',
    wickDownColor: '#ef5350',
});

Actual behavior:

always show the last bar's price, not the last visible one.

Expected behavior:

always show the last bar's price, not the last visible one.

Screenshots:

GIF 2023-10-21 17-10-20

CodeSandbox/JSFiddle/etc link:

https://tradingview.github.io/lightweight-charts/docs/series-types#candlestick

and adding the priceLineSource option

edew commented 1 year ago

If you want the price line source to be the last visible bar then you should use LastVisible, not LastBar.

liesauer commented 1 year ago

If you want the price line source to be the last visible bar then you should use LastVisible, not LastBar.

i need the last bar, but it doesn't work.

SlicedSilver commented 1 year ago

There is probably some confusion about what the expected behaviour is so let me clarify this in more detail.

The priceLineSource sets which value is used for drawing the horizontal price line for that series. The two options are LastVisible (which will draw the line at the price value of the last visible price), and LastBar (which will draw at the latest price, even if it is scrolled out of view). This is working as expected. The line will be drawn at different places.

Where the confusion is probably coming in is that the label on the price scale isn't attached to the price line, but is actually always meant to show the price of the last visible bar. This can be seen by reading the description in the docs:

Visibility of the label with the latest visible price on the price scale.

So again, it is expected that the price label isn't affected by the priceLineSource option.


There is a way to get your desired behaviour.

// and if you need to update the position you could do this: priceLine.applyOptions({ price: 480, / new updated latest price value / });



Here is an example showing the three different options: 
[codesandbox.io](https://codesandbox.io/p/sandbox/lightweight-charts-ts-starter-forked-jhygfw?file=%2F.codesandbox%2Ftasks.json%3A1%2C1)
liesauer commented 1 year ago

i see, so the priceLineSourceonly affects the line, the label always show the price of the last visible bar! it makes me so confused.

liesauer commented 1 year ago

btw, it there any usecases in real world? i really don't understand this out of sync behaviour.