Adding FontAwesome icons to a D3 graph

后端 未结 9 2248
既然无缘
既然无缘 2020-11-27 12:07

I am trying to set an icon with FontAwesome instead of text in my D3 nodes. This is the original implmentation, with text:

g.append(\'svg:text\')
    .attr(\         


        
9条回答
  •  忘掉有多难
    2020-11-27 12:24

    For those who want to use svg icons from FontAwesome with D3, this snippet should work:

    btnGroup.append("g")
      .attr("width", 16)
      .attr("height", 16)
      .attr("class", "fas fa-check-square");
    

    The only drawback here is that width and height are not inherited from CSS. The good news is that class toggling works as expected with d3 and jquery.

    Demo with toggling on click: https://jsfiddle.net/diafour/6fagxpt0/

提交回复
热议问题