简体   繁体   中英

adding style for the text tag in svg elements

I have a graph dynamically created so the svg contains a part with the following code. bt im unable to give background-color to this class.. ive tried it dynamically with the attr() function, but it doesnt work that way.. is there anyway to specify the css like 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>

dynamic creation of svg text

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM