简体   繁体   English

色阶在D3中的树形图中不起作用

[英]Color scale not working in treemap in d3

I am trying to create a Treemap in d3 using csv file. 我正在尝试使用csv文件在d3中创建树形图。 However color scale / color coding does not seem to work for the treemap. 但是,色标/颜色编码似乎不适用于树图。 I tried hardcoding the color for the rectangles even then it doesn't work. 我尝试对矩形的颜色进行硬编码,即使这样不起作用。

You can have a look at my html, js, css, & .csv files in the below link. 您可以在下面的链接中查看我的html,js,css和.csv文件。 http://bl.ocks.org/geetanjalirana/bcfcf2c66609193f75a7 http://bl.ocks.org/geetanjalirana/bcfcf2c66609193f75a7

Kindly suggest where am I going wrong. 请建议我要去哪里错了。

Thanks in advance. 提前致谢。 Geetanjali 吉塔尼亚利

Two changes needed in your current code: In your NewFile.css add fill:none !important; 当前代码中需要进行两项更改:在NewFile.css中添加fill:none!important; do

rect.parent {
    pointer-events: all; 
    fill:none !important;
}

In your NewFile.js in your rect do this you need to add the fill style attribute . 在rect的NewFile.js中,您需要添加fill style属性

function rect(rect) {
    rect.attr("x", function(d) { return x(d.x); })
        .attr("y", function(d) { return y(d.y); })
        .attr("width", function(d) { return x(d.x + d.dx)  - x(d.x); })
        .attr("height", function(d) { return y(d.y + d.dy) - y(d.y); })
    //  .style("background", function(d) { return d.parent ? null : data_colorScale(d.parent.name); });
        .style("fill", function(d) { 
            return d.parent ? data_colorScale(d.parent.name) : null; 
          });
    //  .style("background", "red" });
    //  .attr("fill", function(d) { data_colorScale(d.parent.name); });
}

Hope this helps! 希望这可以帮助!

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

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