Append DOM element to the D3

前端 未结 3 2045
故里飘歌
故里飘歌 2020-12-16 01:01

I\'m using D3 for drawing on the SVG. What I want is to append DOM element or HTML to the D3, like:

task.append(function(model){
//here return html or dom
};         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-16 01:20

    This is how used this information to create dynamic "shapes" in my force-directed chart using a function inside append().

    shape = svg.append("g")
      .selectAll("rect") // only a placeholder - does not control the shape
      .data(force.nodes())
      .enter()
      .append(function(d){
       return setshvape(d)
        })
    
    
    function setshape(d){
       if(d.type == "start"){
         var shape = document.createElementNS(d3.ns.prefix.svg, "circle");
       }else{
        var shape = document.createElementNS(d3.ns.prefix.svg, "rect");
        }
    return shape
    }
    

提交回复
热议问题