亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

確定段落的高度

確定段落的高度

繁星淼淼 2023-07-06 17:18:26
我創建了表格行標題,如下所示。我想在這 4 個標題中創建一個矩形 svg 框。我無法確定段落高度,因此無法創建完全適合段落的框。這是我的代碼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"  ]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")    .style("font", 50)    .html((d,i)=>"<p>"+text[i]+"</p>") https://codepen.io/zubair57/pen/MWeXPqX
查看完整描述

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>


查看完整回答
反對 回復 2023-07-06
  • 1 回答
  • 0 關注
  • 152 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號