简体   繁体   中英

Translate it to another position using d3

I want to translate the svg from (0,0) (initial position) to position say(500,50). For this I am using the below code but it is not working.Please suggest me some idea.

var svg = d3.select("body")
        .append("svg:svg")
        .attr("width", 600)
        .attr("height", 600)
        .append("g")
        .attr("transform","translate(500,50)");

Your code is setting the transform attribute on the g element. Thus, the g element will be translated inside the svg element. If you intended to translate the svg element then set the style attribute on the svg element with the desired transform. Remember to include the units on the translate distances. For example...

var svg = d3.select("body")
.append("svg:svg")
.attr("width", 600)
.attr("height", 600)
.attr("style", "transform: translate(500px,50px)")
.append("g")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM