我试图获取相对于group元素的鼠标坐标。这是代码:
var backRect = chart.append("g").attr("class", "rect");
var g = backRect.append('rect')
.style('stroke', 'none')
.style('fill', '#FFF')
.style('fill-opacity', 0)
.attr({
width: width,
height: height,
'pointer-events': 'none',
'class': 'backRect'
});
// the code below is inside another container's event; but I want mouse coordinates relative to the above rect, hence can't use d3.mouse(this)
// get mouse pointer location
var coordinates = [0, 0];
coordinates = d3.mouse(backRect); // d3.select(".rect") does not work either
Run Code Online (Sandbox Code Playgroud)
但出现以下错误:
d3.min.js:1 Uncaught TypeError: n.getBoundingClientRect is not a function
根据d3 鼠标, docs d3.mouse()会使用一个可以是svg或g元素的容器。
我应该传递给什么参数d3.mouse()?我尝试了d3.select(".rect")哪一种也不起作用。
| 归档时间: |
|
| 查看次数: |
1566 次 |
| 最近记录: |