2012-07-27 157 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( ))。希望这可以帮助。