如何添加链接到d3雷达图的每个节点?

时间:2015-06-22 14:14:31

标签: html d3.js

我已经在我的项目中集成了雷达图表-d3,我想添加一个链接到它的每个节点,以便点击它我可以显示记录详细信息。请帮助。  you can see the demo here enter image description here

1 个答案:

答案 0 :(得分: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