tradingview / charting-library-examples

Examples of Charting Library integrations with other libraries, frameworks and data transports
MIT License
1.33k stars 744 forks source link

Crosshair related API #306

Open XQ-0 opened 1 year ago

XQ-0 commented 1 year ago
XQ-0 commented 1 year ago

How to get the position of the mouse when moving

serhatopcu commented 1 year ago
    tvWidget.onChartReady(() =>  {   
      let crosshairValue;

      const crosshairMovedHandler = (params) => {
       crosshairValue = params;
      };

      tvWidget.activeChart().crossHairMoved().subscribe(null, crosshairMovedHandler);

      tvWidget.subscribe('mouse_down', () => {
       const mouseUpHandler = () => {
        console.log(crosshairValue);
        tvWidget.unsubscribe('mouse_up', mouseUpHandler);
       };

       tvWidget.subscribe('mouse_up', mouseUpHandler);
      });
    }