【发布时间】:2016-07-24 17:58:00
【问题描述】:
我正在学习 SVG,并且有一个非常简单的问题,我真的很苦恼。 如何将文本附加到 svg 标签? 我想达到以下结果:
我正在这样做:
svg.append("text")
.attr("x", width / 2)
.attr("y", height - marginBottom / 1 * 2 )
.text("text 2")
.attr("fill","#808080")
.attr("text-anchor","middle")
.css("font-size", "14px");
但是浏览器显示错误:
未捕获的类型错误: svg.append(...).attr(...).attr(...).text(...).attr(...).attr(...).css 不是函数。
但同时对于<line> svg.append 有效:
svg.append("line")
.attr("y1", height - marginBottom / 3 * 2 )
.attr("y2", height - marginBottom / 3 * 2 )
.attr("x1", marginLeft / 3 * 2 )
.attr("x2", width - 20 )
.attr("stroke-width", 1)
.attr("stroke", "#5A97C3");
请帮助我理解。
【问题讨论】:
标签: javascript html d3.js svg