使用dc.js(d3.js)并尝试将x轴突出显示为0

时间:2015-04-21 17:06:04

标签: css d3.js dc.js

我想在值0处突出显示x轴,以便在值变为负值时很容易看到。我试图在一个renderlet中做这个。我可以看到,当y1属性值等于y2属性值时,x轴为0。因此,在渲染中我试图选择线条,获取y1,y2值,然后当它们相等时,将某些东西应用到线条以使其突出。有没有人这样做?有没有更简单的方法。我有元素和选择器的照片。我只能从renderlet中的选择器中获取y1,y2属性。

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

我不明白你的陈述:

  当y1属性值等于y2时,

x轴为0   属性值

因为您正在查看水平网格线。 y1将始终等于y2,这是一条平坦的水平线。

那说,找到它们:

d3.selectAll('.grid-line.horizontal line').each(function(d){
    var self = d3.select(this);
    if (self.attr('y1') === self.attr('y2')){
        console.log('do something special');
    }
});