在svg元素中添加文本标记的样式

时间:2013-02-24 14:05:50

标签: javascript jquery svg

我有一个动态创建的图表,因此svg包含一个包含以下代码的部分。 我无法给这个类的背景颜色..我已经尝试使用attr()函数动态,但它不会这样工作.. 无论如何要指定像svg:text ??

这样的CSS
<text id="circleText_Persons-bruno-waterfield" font-size="14" class="circleText" font-family="Tahoma" text-anchor="middle" background-color="#000000" font-weight="900" display="block" x="-1.8714285714285717" y="28.711414285714287" fill-opacity="1" stroke-opacity="1" style="fill: #666666;">Bruno Waterfield</text>

动态创建svg文本

      nodeEnter.append("svg:text") 
  .attr("id", function(d){  return "circleText_" + d.name})
      .attr("font-size", function(d){return 14;}) //returnNodeSize(d) / 2
      .attr("class",  function(d){return "circleText"}).attr("font-family", "Tahoma")
      .attr("text-anchor","middle")
      .attr("background-color","#000000")
      .attr("font-weight","900")
      //returnNodeSize(d)+returnNodeSize(d)/1.8;
       .text(function(d){ 

         return toTitleCase(d.name));

1 个答案:

答案 0 :(得分:0)

将所选颜色的rect放在符合文本边界框的text元素后面。 SVG文本没有用于设置背景颜色的流程框;你必须做一个。