问题
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