D3 - Add a raw symbol

↘锁芯ラ 提交于 2019-12-25 07:30:13

问题


I have a D3 code.

I want to add a svg symbol "as is"! to the D3 svg.

I dont want to create the symbol dynamically using D3, I have the symbols already made from our designer and i want to use it as is!

This is my jsfiddle: https://jsfiddle.net/omriman12/8786e8zq/1/

In the fiddle I have my d3 container pie_chart_wrapper and i want to add the symbol md_file to the d3 svg


回答1:


Just add previous definded symbol to your SVG:

svg.append("g")
   .attr("transform","translate(0,0)")
   .attr("class","mySymbol")
   .append("use")
   .attr("xlink:href","#md_file")

Here the working code

After append use your can tweak their attributes, like so:

svg.append("g")
   .attr("transform","translate(0,0)")
   .attr("class","mySymbol")
   .append("use")
   .attr("width",20)
   .attr("heigth", 20)
   .style("fill", "red")
       .
       .
       .
   .attr("xlink:href","#md_file")


来源:https://stackoverflow.com/questions/38170380/d3-add-a-raw-symbol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!