anycharts.com how to retrieve Y value of price pointed at by mouse

33 Views Asked by At

Anycharts.com has wonderful javascript libraries to create stock charts. It is however complicated to get a mouse Y value, only a (X,Y) value of an object in the chart.

I tried everything from using the crosshair (sticks to the candles), the mouseclick event etcetera but I have so far not been able to solve this. I hoped to get the labelValue and hoped this would be the mouse coordinate in the labelValue but it turns out to be the Y coordinate of object where the crosshairs would be. For example:

            chart.tooltip().format(function(e){
                            myLastIndex = e.index;
                            myLastDate = e.x;
                            let label = plot.crosshair().yLabel();
                            let labelValue = label.text();
                            myLastHigh = parseFloat(labelValue);
                    });
1

There are 1 best solutions below

0
Adriaan Bakker On

After enough fiddling around, found that changing the crosshair setting from "sticky" to "float" was the answer.

let chart = anychart.stock();
var crosshair = chart.crosshair();
crosshair.enabled(true);
 
// Set display mode.
crosshair.displayMode('float');