gpt4 book ai didi

javascript - 通过将鼠标悬停在节点上突出显示 D3 中的边缘

转载 作者:行者123 更新时间:2023-11-28 07:43:06 26 4
gpt4 key购买 nike

我是 D3 新手,我正在使用此模板 ( http://bl.ocks.org/mbostock/1153292 ) 来可视化我的图表。我想通过将鼠标悬停在节点上来突出显示连接到该节点的链接。我通过将以下几行添加到脚本中尝试了 ( http://jsfiddle.net/2pdxz/2/ ) 中使用的技术。

nodes.on('mouseover', function(d) {
link.style('stroke-width', function(l) {
if (d === l.source || d === l.target)
return 4;
else
return 2;
});
});

// Set the stroke width back to normal when mouse leaves the node.
nodes.on('mouseout', function() {
link.style('stroke-width', 2);
});

但它似乎对我不起作用,当我将鼠标移到节点上时没有任何反应。

最佳答案

正如评论中所指出的,代码的基本原理是正确的,问题是 link 变量应该被命名为 path

关于javascript - 通过将鼠标悬停在节点上突出显示 D3 中的边缘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27785505/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com