简体   繁体   English

在节点和链接的典型图中将附加到节点的图像的文本标题转换为D3中的图像

[英]Convert text header of image appended to node in typical graph of nodes and link, to image in D3

I would like to add header to my nodes in d3. 我想将标题添加到d3中的节点。 But instead of appending it as text I want to append it as image so that in graph scenario all lines will be below header and picture will look cleaner. 但是,我不想将其附加为文本,而是希望将其附加为图像,以便在图形方案中所有行都位于标题下方,图片看起来更清晰。

Currently because of many links picture looks messy which I want to avoid. 目前由于许多链接,图片看起来很乱,我想避免。

node.append('text')
.attr("class","label")
.attr("style","font-size:12px;")
.html(function(d){ 
        return d.name;  
    }
})
.attr("x",0)
.attr("y",-radius);

Is there any way how to do this. 有什么办法可以做到这一点。 I read about hidden canvas but not sure exactly how to use here as I am beginner in D3. 我读过有关隐藏的画布的信息,但由于我是D3的初学者,因此不确定确切的用法。

Thanks 谢谢

You can append an image as well. 您也可以附加图像

I've set up a fiddle here, to showcase a working example of appending an image(icon) inside a circle. 我在这里设置了一个小提琴 ,以演示在圆内附加图像(图标)的工作示例。

node.append("circle")
         .attr("cursor","pointer")
          .attr("cx", 200)
         .attr("cy", 200)
         .attr("r", 25)
         .style("fill","white")
         .style("stroke", "black")     
         .style("stroke-width", 2);

node.append("image")
    .attr("xlink:href", "http://i.stack.imgur.com/bZXWH.png")
    .attr("x", 185)
    .attr("y", 185)
    .attr("width", 32)
    .attr("height", 32);

You might also find this tutorial helpful. 您可能还会发现本教程很有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM