2015-06-22 44 views
1

我在我的項目中集成了radar-chart-d3,我想添加一個鏈接到它的每個節點,以便它的onclick我可以顯示記錄details.please幫助。 you can see the demo hereenter image description here如何添加鏈接到d3雷達圖的每個節點?

+0

您需要爲這些元素添加一個'onclick'事件處理程序。 –

+0

Tanx爲您的好建議親愛的Lars,但我需要添加onclick,因爲我是新的d3和JavaScript ??/ – jones

+0

關於你想成爲「活躍」的元素 - 使用'.on(「click」,函數(){/ *處理程序* /})'在包含這些元素的選擇。 –

回答

1

由於您使用的雷達圖實現是黑箱,我想補充的鏈接它呈現後:

// this "circles" are where you want your links 
svg.selectAll('.circle').each(function(d,i){ 

    // get the parent of each circle, we'll append the link to this 
    var par = d3.select(this.parentNode); 

    // create the link and text 
    par.append("a") 
    .attr("xlink:href", "http://www.google.com") 
    .attr("target","_blank") 
    .append("text") 
    .attr("transform", "translate("+ (d[0].x) +","+ (d[0].y) +")") // where to place it! 
    .text("this is a link"); 
}); 

here

+0

非常感謝Mark。你的答案可以幫助我。以及如何爲每個節點添加不同的鏈接。 – jones

+0

@jones,將它們添加到您的數據並將它們讀出來。更新示例:http://plnkr.co/edit/X1yEuP7iYQw9L7cSDZyH?p=preview – Mark