简体   繁体   English

D3为CSS颜色,用于堆叠条形图

[英]D3 to CSS color for stacked bar graph

I am trying to implement color in stacked bar chart in D3 using CSS. 我正在尝试使用CSS在D3的堆叠条形图中实现颜色。 Right now in D3 we are creating the bar chart using enter, update, exit using color like below. 现在在D3中,我们使用如下所示的颜色使用enter,update,exit创建条形图。 The i in the code is the index. 代码中的i是索引。

    var stackedBarEnter = stackedBar.enter()
        .append('g')
        .attr('class', function(d,i) {
            return 'stacked bar color-'+i;
});

In CSS I have tried different things: .rect stacked bar color-[0] rect { fill:red; 在CSS中,我尝试了不同的方法:.rect堆叠的条形color- [0] rect {fill:red; } }

Is there anything I am doing wrong, or any suggestions regarding how I could fill color in CSS? 我做错了什么吗,或者关于如何在CSS中填充颜色的任何建议? We were told previously that we should be doing it just like this pseudo-code: {fill: red;} 之前我们被告知,我们应该像下面的伪代码那样进行操作:{fill:red;}

In your current little code blurb you don't have a .rect class to select. 在当前的小代码内容中,您没有.rect类可供选择。 Try using g .stacked .bar .color-[0] {fill:red;} 尝试使用g .stacked .bar .color- [0] {fill:red;}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM