tradingview / lightweight-charts

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

Add custom price lines #183

Closed primozv closed 4 years ago

primozv commented 5 years ago

Describe the solution you'd like

There is a price line added for the price matching the last price in the data. It can be removed by setting priceLineVisible to false. Is it possible to add a custom price line that would mark specific price not matching the last price. Or multiple custom price lines. If not can that feature be added. Sometimes we need to mark a specific value that the histogram needs to reach, or 20%/80% values of the price graph.

timocov commented 5 years ago

As workaround you can create a series on the level you want to show (something like in #116).

odlainepre commented 4 years ago

ref: https://github.com/tradingview/lightweight-charts/issues/194

Hi! Need custom price line. As in the private lib tvWidget.chart (). CreateOrderLine ({})

This option is very necessary for production, if possible, add in 1.2.0.

My case: need to display orders. Private library charting_library is very heavy. Only this functionality is not enough to start production version of my project.

eugene-korobko commented 4 years ago

I'd like suggesting following approach:

Add two methods to ISeriesApi:

createPriceLine(options: PriceLineOptions): IPriceLine;
removePriceLine(IPriceLine): void;

PriceLineOptions - is an interface with structure

{
    level: BarPrice | BarPriceProvider,
    color: string,
    lineWidth: LineWidth,
    lineStyle: LineStyle,
}

where


BarPriceProvider = (series: ISeries) => BarPrice

So we will support both push and pull approaches to get price line level value. I'm not sure about cases where pulling would be more effective. We could postpone it so far.

interface IPriceLine is very simple:

applyOptions(options: Partial<PriceLineOptions>): void;
options(): Readonly<PriceLineOptions>;

applyOptions could be used to change color/style as well as price level

timocov commented 4 years ago

@eugene-korobko

level: BarPrice | BarPriceProvider

By default the library doesn't repaint if nothing is changed. How in case of BarPriceProvider the library will know that it needed to be repainted?

What's about price range? Should price line extend price range or not (in autoscale mode)? Should we have option for that?

Others looks fine for me.

@nikitamarcius please note that the first version will not support drawing text for price lines (on, above or even below).

odlainepre commented 4 years ago

Add plz in 1.3.0 text for priceLine

timocov commented 4 years ago

@nikitamarcius I guess it's something like #278. Anyway, it should be separate issue :)

odlainepre commented 4 years ago

@timocov agree

HighBreedTech commented 4 years ago

please i need help on https://github.com/tradingview/lightweight-charts/issues/348