Closed liesauer closed 11 months ago
If you want the price line source to be the last visible bar then you should use LastVisible
, not LastBar
.
If you want the price line source to be the last visible bar then you should use
LastVisible
, notLastBar
.
i need the last bar, but it doesn't work.
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.
lastValueVisible
to false
so that the label is not visiblepriceLineVisible
to false
so that the price line isn't visible
const priceLine = mainSeries.createPriceLine({
price: 460.0, /* latest price value */
color: "red",
lineWidth: 1,
axisLabelVisible: true,
});
// 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)
i see, so the priceLineSource
only affects the line, the label always show the price of the last visible bar! it makes me so confused.
btw, it there any usecases in real world? i really don't understand this out of sync behaviour.
Lightweight Charts™ Version: 4.1.0
Steps/code to reproduce:
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:
CodeSandbox/JSFiddle/etc link:
https://tradingview.github.io/lightweight-charts/docs/series-types#candlestick
and adding the
priceLineSource
option