1
我是新来的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);
});
但它似乎不适合我,当我将鼠标移动到节点上时没有任何反应。
这对工作的正确的代码,当你CONSOLE.LOG(L)和执行console.log(d)会发生什么?我想你会在某处覆盖一个变量。 – Elijah
当我将鼠标悬停在节点上时,我在控制台上收到此错误:“未捕获的TypeError:undefined不是函数”。这里是链接到的jsfiddle:发现问题,并固定它http://jsfiddle.net/bswv1mqe/ – Mohsen
!我不得不使用路径而不是链接... – Mohsen