2015-01-05 152 views
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); 
}); 

但它似乎不適合我,當我將鼠標移動到節點上時沒有任何反應。

+0

這對工作的正確的代碼,當你CONSOLE.LOG(L)和執行console.log(d)會發生什麼?我想你會在某處覆蓋一個變量。 – Elijah

+0

當我將鼠標懸停在節點上時,我在控制檯上收到此錯誤:「未捕獲的TypeError:undefined不是函數」。這裏是鏈接到的jsfiddle:發現問題,並固定它http://jsfiddle.net/bswv1mqe/ – Mohsen

+0

!我不得不使用路徑而不是鏈接... – Mohsen

回答

0

正如評論中指出的那樣,代碼的基礎是正確的,問題在於link變量應該被命名爲path