D3.js特定刻度样式

时间:2014-02-21 16:20:14

标签: css3 svg d3.js nvd3.js

如果我使用x [0,100]和y [0,100]并且我想只为(0,50)和(50,0)绘制或设置样式,是否有一种方法可以设置特定刻度的样式?

1 个答案:

答案 0 :(得分:18)

由d3轴函数创建的刻度具有与其绑定的刻度值作为数据对象。绘制轴后,您可以重新选择刻度并根据其数据对其进行操作。

例如,您可以过滤选择以仅查找具有特定值的刻度。然后,您可以应用与任何其他d3选择相同的样式或类。

d3.selectAll('g.tick')
  .filter(function(d){ return d==50;} )
   //only ticks that returned true for the filter will be included
   //in the rest of the method calls:
  .select('line') //grab the tick line
  .attr('class', 'quadrantBorder') //style with a custom class and CSS
  .style('stroke-width', 5); //or style directly with attributes or inline styles

更多解释和另一个例子,在属性调用中使用基于数据的函数而不是使用过滤器:
https://stackoverflow.com/a/21583985/3128209

相关问题