[借助协助,我发现了改变径向树状图元素的方法。下面的行执行该功能。但是,我试图用相同的鼠标悬停在加粗文本上。有人可以告诉我我所缺少的吗?
//当鼠标悬停在节点上时,负责更改节点的样式和类型
d3.selectAll('g.node').attr("id", function(d,i){ return "node"+i});
d3.selectAll('path.link').attr("id", function(d,i){ return "link"+i}); //my guess is on the line
below
d3.selectAll('text').attr("id", function(d,i){ return "text"+i});
//仍在尝试弄清楚如何将鼠标悬停在文本上以粗体显示
d3.selectAll('g.node').each(function(d, i) {
d3.select('#node'+i).on("mouseover", function() {
d3.select('#link'+(i-1))
.attr('style','stroke-width: 4px','style','font-weight: bold'); // my 2nd guess is on the next
line
d3.select('text').attr("font-weight",function(d,i) {return i*800+800;});
})。on(“ mouseout”,function(){d3.select('#link'+(i-1))。attr('style','stroke-width:1.5px','stroke-opacity:0.4','stroke:#555');});});
为了设置font-weight
-which is a CSS property-,应使用.style
代替.attr
:
d3.select('#link'+(i-1))
.style('font-weight','bold');
有用的参考:modifying elements和d3-selection
。