Dmi*_*try 3 javascript svg d3.js
我创建了一个带有某些节点的SVG元素:
gnodes = svg.selectAll("g.node")
.data(_nodes);
var newNodes = gnodes.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
.call(drag)
.on('mouseover', onMouseOver)
.on('mouseout', onMouseOut);
newNodes.append("circle")
.attr("cx", 0)
.attr("cy", 0)
.attr("r", radius);
newNodes.append("image")
.attr("xlink:href", getImage)
.attr("x", -radius/2)
.attr("y", -radius/2)
.attr("width", radius + "px")
.attr("height", radius + "px");
Run Code Online (Sandbox Code Playgroud)
在onMouseOver中,我想更改突出显示的圆圈的颜色,但是我无法从收到的数据中获得此项目:
function onMouseOver(d, i) {
var c1 = d.select("circle"); // error
var c2 = i.select("circle"); // error
var c3 = d.selectAll("circle"); // error
var c4 = i.selectAll("circle"); // error
}
Run Code Online (Sandbox Code Playgroud)
用d3获取子节点的方法是什么?
d是数据对象和i索引。两者都不是提供对任何d3 select函数的访问的d3实例。
尝试这个:
myelement.on('mouseenter', function(d,i) {
d3.select(this).select('circle');
});
Run Code Online (Sandbox Code Playgroud)