tradingview / lightweight-charts

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

API to get color of the bar/candlestick item #518

Closed nakcyber closed 1 year ago

nakcyber commented 4 years ago

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

timocov commented 4 years ago

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).

emrahtunc14 commented 2 years ago

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

emrahtunc14 commented 2 years ago

any body here?

SlicedSilver commented 1 year ago

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.