简体   繁体   English

D3森伯斯特图上的同心颜色

[英]Concentric colours on D3 Sunburst diagram

I have a Sunburst diagram which uses essentially the same code as the standard at http://bl.ocks.org/kerryrodden/7090426 . 我有一个森伯斯特图,它使用的代码与http://bl.ocks.org/kerryrodden/7090426的标准代码基本相同。

However, I have many many 'nodes' in my final two rings and any combination of colours makes it look extremely messy. 但是,最后两个环中有许多“节点”,并且颜色的任意组合都使它看起来极为混乱。 As each node within the diagram is pulled from a database I'm unable to assign specific colours to values as the values are all unique. 由于图中的每个节点都是从数据库中提取的,因此我无法为值分配特定的颜色,因为这些值都是唯一的。

Is there a way that I could specify a colour for the entirety of each individual ring in the diagram? 有没有一种方法可以为图中每个环的整体指定颜色? As an example, I would like it to look somewhat like this: 例如,我希望它看起来像这样:

http://www.design-by-izo.com/wp-content/uploads/2011/02/Krakow-3.jpg http://www.design-by-izo.com/wp-content/uploads/2011/02/Krakow-3.jpg

That way I would be able to come up with a palette that doesn't clash as much as applying range of colours that d3 just cycles through. 这样,我将能够提出一个不会像应用d3循环显示的颜色范围那样引起冲突的调色板。

From what I understand, you can simply change the fill style in the diagram, using depth of the respective data, like so: 据我了解,您可以使用相应数据的depth来简单地更改图中的fill样式,如下所示:

.style('fill', function (d) {
    return color(d.depth);
})

where color is some sort of a color array. 其中color是某种颜色数组。

Alternatively, ES6/2015, just: 另外,ES6 / 2015仅:

.style('fill', d => color(d.depth))

Here's a fiddle, showing you the effect: Fiddle (based on this ) 这是一个小提琴,向您展示了效果: 小提琴 (基于

I hope this is what you want. 我希望这就是你想要的。

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

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