Search code examples
javascriptlightweight-charts

Detect if Crosshair is present/visible - TradingView Lightweight Charts


Is there a way to detect whether the crosshair is currently visible/shown on the chart? I see these options that set crosshair settings, but no boolean/API to detect whether the crosshair is currently shown. Any ideas? Should I simply detect using javascript and divElement.getBoundingClientRect(); on mouseMove/touchMove?


Solution

  • There is no property to track that on the chart object, but you can track it yourself using subscribeCrosshairMove event handler, when the param.point become null that means that the cursor is out of the chart, and when the user points to the chart again the point x/y will get some values.

    chart.subscribeCrosshairMove(param => {
      console.log(param.point)
    })