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

API to get color of the bar/candlestick item

Open nakcyber opened this issue 5 years ago • 3 comments

Hi, lightweight-charts team Is it possible to get barStyle() via an index in the series chart in lightweight-charts v3.1.2 ? I used to barStyle() for get color in lightweight-charts v2.0.0

var candleSeries = chart.addCandlestickSeries();
var color = candleSeries.series().barColorer().barStyle(index);

example Information obtained from the barStyle() { barBorderColor: "rgb(229, 68, 95)" barColor: "rgb(229, 68, 95)" barWickColor: "rgb(229, 68, 95)" }

Now it doesn't work. Can I have another method to use instead?

I want to get barStyle() method because my app chart has a legend feature a color the same as the bar color.

image image image

Lightweight Charts Version: 3.1.2

nakcyber avatar Jul 08 '20 02:07 nakcyber

The issue we need to pay attention here is custom colors per bar item (available for histogram atm, but could be implemented in other series soon in #195). If you don't use custom colors - you can do it easily by getting color from options (for bars logic of choosing a color is pretty simple).

timocov avatar Jul 09 '20 07:07 timocov

How can I get the candle color on mouseover from charts that are like candle type?

emrahtunc14 avatar Jul 06 '22 16:07 emrahtunc14

any body here?

emrahtunc14 avatar Jul 07 '22 08:07 emrahtunc14

At the moment, you can't get the colour directly from the API but you can work around this to get it working.

The colour of the candlestick is either based on whether the it is higher or lower than the previous value, or set by the data itself.

The crosshair event (https://tradingview.github.io/lightweight-charts/docs/api/interfaces/IChartApi#subscribecrosshairmove) contains a time property which you could use to either check the colour you've set in the data, or find the previous value and compare it's value to determine the expect colour.

SlicedSilver avatar Aug 26 '22 15:08 SlicedSilver