2015-06-22 42 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