How to move SVG's position in D3?

前端 未结 4 2517
孤城傲影
孤城傲影 2021-02-20 07:35

I created a svg using D3. However, it only shows up on the upper left conner of the screen, or been appended to another svg. Are there anyway I can move it using JavaScript? For

4条回答
  •  滥情空心
    2021-02-20 08:15

    Using d3js + Jquery :

    // svg design
    var svg = d3.select("#chart").append("svg")
        .attr("width", 200)
        .attr("height", 200);
    
    // svg repositioning
    $("svg").css({top: 200, left: 200, position:'absolute'});
    

    Or

    // svg align center
    d3.select("#chart").attr("align","center"); //  thanks & +1 to chaitanya89
    

    Live demo

提交回复
热议问题