1 回答
TA贡献1799条经验 获得超8个赞
let svg = d3.select("body").append("svg").attr("width", 1000).attr("height", 1000);
let text=[
"Who will win the election. Trump or Biden?",
"Data Analysis",
"Javascript",
"Compare Performance of S&P 500 Index against other Indices"
]
let texty=svg.selectAll("boxestext")
.data([0,100,200,300])
.enter()
.append("foreignObject")
.attr("width", (d, i) => 100 )
.attr("height", 200)
.attr("x",(d, i) => d)
.attr("y",0)
.attr("class", "boxes")
.append("xhtml:body")
.attr("class","mytext")
.attr("id",(d,i)=>"mytext"+i)
.style("font", 50)
.html((d,i)=>"<p>"+text[i]+"</p>")
let rect = d3.selectAll("p").node().getBoundingClientRect()
console.log(rect.height)///
p {text-align: left;}
.boxes p{
border:1px solid;
}
<script src="https://d3js.org/d3.v5.min.js"></script>
添加回答
举报