D3 SVG插入问题

时间:2019-05-01 12:27:05

标签: d3.js dom

我正在尝试使用D3将一段HTML插入到现有的SVG中,不幸的是看到此帖子https://gist.github.com/biovisualize/373c6216b5634327099a在版本5中似乎已弃用。现在,添加以下HTML的最佳实践是什么?到现有的SVG元素

 //select the relevant element in the DOM and add an SVG element to it
 var svg = d3.select("#chart-area").append("svg")
 .attr("width", width + margin.left + margin.right)
 .attr("height", height + margin.bottom + margin.top);

 //split the chart into left and right
 var gLeft = gWhole.append("g").attr("class","gLeft") 
 var gRight = gWhole.append("g").attr("class","gRight").attr("transform",`translate(${width/2+50},0)`).attr("fill","red");  

//need to append the following to gRight
<svg><g id="hideAC"><circle class="close" cx="10" cy="10" r="9.5"/><path 
class="close2" d="M10,1a9,9,0,1,1-9,9,9,9,0,0,1,9-9m0- 
1A10,10,0,1,0,20,10,10,10,0,0,0,10,0Z"/><polygon class="cls-2" points="10 
11.18 6.11 14.6 5.31 12.94 8.66 10 5.31 7.06 6.11 5.41 10 8.82 13.89 5.41 
14.69 7.06 11.34 10 14.69 12.94 13.89 14.6 10 11.18"/><path 
d="M13.81,5.81,14.38,7l-3,2.62L11,10l.43.38,3,2.62-.57,1.19-3.48- 
3L10,10.85l-.33.29-3.48,3L5.62,13l3-2.62L9,10l-.43-.38L5.62,7l.57- 
1.19L9.67,8.86l.33.29.33-.29,3.48- 
3M14,5,10,8.49,6,5,5,7.12,8.28,10,5,12.88,6,15l4-3.49L14,15l1- 
2.12L11.72,10,15,7.12,14,5Z"/></g></svg>

0 个答案:

没有答案