【发布时间】:2013-08-27 07:50:28
【问题描述】:
我试图在我的 D3 节点中设置一个带有 FontAwesome 的图标,而不是文本。这是原来的实现,带文字:
g.append('svg:text')
.attr('x', 0)
.attr('y', 4)
.attr('class', 'id')
.text(function(d) { return d.label; });
现在我尝试使用图标:
g.append('svg:i')
.attr('x', 0)
.attr('y', 4)
.attr('class', 'id icon-fixed-width icon-user');
但这不起作用,即使标记是正确的,并且 CSS 规则被正确命中:图标不可见。
知道为什么吗?
这里是相关的jsbin
编辑
我找到了插入图片的替代方法:http://bl.ocks.org/mbostock/950642
node.append("image")
.attr("xlink:href", "https://github.com/favicon.ico")
.attr("x", -8)
.attr("y", -8)
.attr("width", 16)
.attr("height", 16);
这正是我想要做的,但它不适用于 FontAwesome 使用的 <i> 元素。
【问题讨论】:
标签: javascript d3.js font-awesome