tradingview / lightweight-charts

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

Get candle data (OHLC) with subscribeCrossHairMove ? #189

Closed odlainepre closed 5 years ago

odlainepre commented 5 years ago

Hi!

How to get candle data (OHLC) with subscribeCrossHairMove ? I can only get the current price.

chart.subscribeCrossHairMove(param => {
    if (param.time) {
        const price = param.seriesPrices.get(this.series)
        row.innerText = 'String' + '  ' + price.toFixed(2)
    } else {
        row.innerText = 'String'
    }
})
pinal-knoxpo commented 5 years ago

@nikitamarcius If you have set data like below object candlestickSeries.setData([ { time: "2018-12-19", open: 141.77, high: 170.39, low: 120.25, close: 145.72 }, { time: "2018-12-20", open: 145.72, high: 147.99, low: 100.11, close: 108.19 } ]); You will get active data i.e. object using const ohlc = param.seriesPrices.get(this.candlestickSeries). i.e -> { open: 141.77, high: 170.39, low: 120.25, close: 145.72 }

odlainepre commented 5 years ago

@pinal-knoxpo thnx, it`s works

https://jsfiddle.net/tpmrjkwz/

UPD: Was version problem, my version was 1.0.0rc2 (return only price), updated to 1.1.0 Stand Alone 1.0.0 also works.