1

我有一个动态创建的图表,因此 svg 包含带有以下代码的部分。bt 我无法为此类提供背景颜色.. 我使用 attr() 函数动态尝试了它,但它不起作用.. 无论如何指定 css 像 svg:text??

<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));
4

1 回答 1

0

Put a rect of your chosen color behind the text element conforming to the bounding box of the text. SVG text does not have a flow box with which to set the background color; you have to make one.

于 2013-02-24T14:17:30.373 回答