如何将超文本链接添加到Cluster Force Layout圈

时间:2016-09-14 06:30:55

标签: d3.js

我有一个群集力布局,工作正常,我可以添加文本到圆圈。但是,当我尝试添加超文本链接时,不会显示任何内容。 我的code有什么问题?

文字的代码是

node.append("a")
    .text(function(d){
        return d.name;
    })
    .attr("href", function(d){
         return '/profile/'+d.name;
    })
    .attr("dx", -10)
    .text(function(d){
         return d.name;
    })
    .style("stroke", "white");

1 个答案:

答案 0 :(得分:1)

在SVG中,您不能将文本内容放入<a>本身。有关<a>元素实际允许内容的概述,请查看规范的Content model部分。

您需要在链接标签周围包含另一个text元素:

node.append("a")
    .attr("xlink:href", function(d){
         return '/profile/'+d.name;
    })
    .append("text")                   // <-- Wrap <text> element around link label
    .text(function(d){
        return d.name;
    })
    .attr("dx", -10)
    .style("stroke", "white");
相关问题