【发布时间】:2014-01-05 19:42:04
【问题描述】:
我希望将 html 附加到 D3 中的矩形上,以提供多行工具提示。底部是我如何添加一个可能是问题的一部分的矩形。顶部是应该在我的世界中工作的代码。
newRect.().html(" <textArea font-family=Verdana font-size=20 fill=blue > Test " + "</br>" + "Test2 </textArea>");
确实在 SVG 中插入了一个文本字段,但它只是不显示:
HTML:
<rect id="rectLabel" x="490" y="674" width="130" height="160" fill="red">
<textarea fill="blue" font-size="20" font-family="Verdana"> Test </br>Test2 </textarea>
</rect>
我有一个鼠标悬停功能,它运行以下内容:
newRect = svg.append("rect")
.attr("x", xCor)
.attr("y", yCor)
.attr("width", 130)
.attr("height", 160)
.attr("fill", "red")
.attr("id", "rectLabel");
我认为我应该这样做,但它不起作用。它只是删除了我试图附加到的 g.node。
newRect = $(this).enter().append("rect")
.attr("x", xCor)
.attr("y", yCor)
.attr("width", 130)
.attr("height", 160)
.attr("fill", "red")
.attr("id", "rectLabel");
问题: 为什么我的文字没有出现?我试过 .html、.textArea。我想要一个多行标签,所以我认为 .text 不能正常工作?另外,我应该如何附加矩形?
【问题讨论】:
标签: javascript svg d3.js