2012-07-27 41 views
4

d3.js中是否有做.axis路徑{fill:none}?在d3.js中設置座標軸的css

我試過在.CALL .attr和.style(d3.svg.axis(),但無濟於事。我只是在這裏做得不對...

完整的代碼,我創建使用我的軸低於:

// create Axis 
    svg.selectAll("axis") 
     .data(d3.range(angle.domain()[1])) 
    .enter().append("g") 
     .attr("class", "axis") 
     .attr("transform", function(d) { return "rotate(" + angle(d) * 180/Math.PI + ")"; }) 
    .call(d3.svg.axis() 
     .scale(radius.copy().range([0,0])) 
     .ticks(1) 
     .tickFormat("") 
     .orient("left")) 
     .attr("fill","none") // EDITED WITH FILL NONE 
    .append("text") 
     .attr("y", 
     function (d) { 
      if (window.innerWidth < 455){ 
      console.log("innerWidth less than 455: ",window.innerWidth); 
      return -(0); 
      } 
      else{ 
      console.log("innerWidth greater than 455: ",window.innerWidth); 
      return -(0); 
      } 
     }) 
     .attr("dy", "0em"); 
+1

你想達到什麼樣的效果? – 2012-07-27 21:26:32

+0

@LarsKotthoff我想追加一些CSS到我的軸來複制.axis路徑{fill:none},它是當前內嵌在html文件中的。我想用d3屬性或樣式替換內聯css – Apollo 2012-07-27 22:11:31

+0

您是否嘗試將'.attr(「fill」,「none」)'直接添加到軸路徑? – 2012-07-27 22:17:31

回答

9

當我想申請CSS設置D3的元素,我覺得這是最簡單的爲它們分配一個ID或類(你在上面做的),然後應用例如,保留上面的JS,然後在css中執行:

.axis path { 

    fill:   none; 
} 

如果你想這樣做的JS,你應該使用:

.style('fill', 'none') 

但是,你應該把它應用到包含軸線,而不是裏面的.CALL(d3.svg.axis的SVG( ))。希望這可以幫助。