2013-02-24 203 views
1

我有一個動態創建的圖形,因此svg包含具有以下代碼的部分。 bt我無法給這個類的背景顏色.. ive與attr()函數動態地嘗試它,但它不工作的方式.. 是否有指定的CSS像SVG:文本?爲svg元素中的文本標籤添加樣式

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

回答

0

的把一個recttext元素符合文本的邊框背後你所選擇的顏色。 SVG文本沒有用於設置背景顏色的流程框;你必須做一個。

+0

我編輯了這個問題...所以如果我添加一個矩形它將像svg:rect:text – 2013-02-24 14:22:58

+0

@SamDaSilva一樣工作不,你需要生成'svg:rect'並將它放在文本元素之前,然後將其x,y,寬度和高度設置爲與以下文本元素相同(一旦知道這些值)。 – Plynx 2013-02-24 14:25:50

相關問題