andredumas / techan.js

A visual, technical analysis and charting (Candlestick, OHLC, indicators) library built on D3.
http://techanjs.org/
MIT License
2.4k stars 537 forks source link

How do I get the value of the candle I clicked? #204

Open sumihiro opened 7 years ago

sumihiro commented 7 years ago

I added a click event based on the graph of the next candle foot. However, the value of the candle clicked cannot be taken. How can I get a value?

http://bl.ocks.org/andredumas/27c4a333b0e0813e093d

svg.selectAll("g.candlestick")
.on('click', function(d,i,x) {
    console.log(d3.select(this).datum()); // will return all of values. I want a value of this item.
});
episage commented 6 years ago

+1

icastillejogomez commented 6 years ago

+1

episage commented 6 years ago

As for me, it turns out that it was easier to "write techan.js in d3" by myself. Seriously, it's not that hard.

icastillejogomez commented 6 years ago

I don’t understand you @episage How did you do it?

briancappello commented 6 years ago

Sorry, I don't have time at this second to expand further, but the short of it is:

https://gist.github.com/briancappello/7eb6ad30846368cf0c7d812439ef9d0f#file-components-chart-crosshairs-js-L59

https://gist.github.com/briancappello/7eb6ad30846368cf0c7d812439ef9d0f#file-components-chart-chart-js-L463

https://gist.github.com/briancappello/7eb6ad30846368cf0c7d812439ef9d0f#file-components-chart-chart-js-L505

https://gist.github.com/briancappello/7eb6ad30846368cf0c7d812439ef9d0f#file-components-chart-chart-js-L398

episage commented 6 years ago

@icastillejogomez I learned https://d3js.org/ and wrote the code for drawing candles myself. It is not that difficult. It took some significant time investment but it was worth it. Now I can draw very customised charts and techan.js doesn't limit me. You can also modify techan.js code but I went the other way.

icastillejogomez commented 6 years ago

In this issue I can get the candle data that my mouse hover it. https://github.com/andredumas/techan.js/issues/226