Javascript 如何计算我的鼠标在d3中的x和y位置?
我正在使用JS、D3、鼠标事件和HTML 当鼠标悬停在SVG上时,我试图找出鼠标的x和y位置 我的代码Javascript 如何计算我的鼠标在d3中的x和y位置?,javascript,html,svg,d3.js,Javascript,Html,Svg,D3.js,我正在使用JS、D3、鼠标事件和HTML 当鼠标悬停在SVG上时,我试图找出鼠标的x和y位置 我的代码 let svg = d3.select("body").append("svg") .attr("width", width) .attr("height", height) .on("mouseover", function(){ let x = d3.
let svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.on("mouseover", function(){
let x = d3.select(this).attr("x")
console.log(x)
})
我在网上查了一下,发现有人在谈论使用d3.mouse(这个),但是我一直在使用d3.mouse()不是一个函数
有人能帮我吗:)
谢谢在D3V6中,
D3.鼠标
变成了D3.指针
:
let svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.on("mouseover", e => console.log(d3.pointer(e)) )
在D3V6中,
D3.鼠标
变成了D3.指针
:
let svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.on("mouseover", e => console.log(d3.pointer(e)) )
您使用的是哪一版本的D3<代码>d3。鼠标变成了最新版本的<代码>d3。指针。谢谢:)把它作为答案,我会标记答案:)你使用的是哪一版本的d3<代码>d3.鼠标在最新版本中变成了<代码>d3.指针。谢谢:)把它作为一个答案,我会标记为回答:)我得到了[undefined,undefined]答案是