How do I get the mouse coordinates using mousedown in d3?

后端 未结 1 542
野的像风
野的像风 2021-01-17 01:01

I am trying to create a graph in D3 where you can draw a square to zoom in. Right now, I am trying to get the mousedown function to work. I need to be able to click anywhere

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-17 01:36

    firstly, you need to set up the click event properly.

    svg.on('mousedown', function() { console.log(d3.event); } );
    

    in your case:

    svg.on('mousedown', mousedown);
    
    function mousedown() {
      console.log(d3.event.clientX);
      console.log(d3.event.clientY);
    }
    

    0 讨论(0)
提交回复
热议问题