问题描述
我尝试使用
,但颜色已更改。
I try to use http://mbostock.github.com/d3/ex/bubble.htmlbut with changed colors.
我想知道如何在d3.layout.pack中设置颜色。
I would like to find out how the colors are set in d3.layout.pack.
推荐答案
在您提到的示例中,圆圈颜色定义如下:
In the example you mentioned, the circle color is defined here:
.style("fill", function(d) { return fill(d.packageName); });
这里, d
在此示例中,函数传递一个对象(packageName属性 d
)而不是颜色。
每个对象根据所选的颜色标度获得分配给它的唯一颜色:
Here, d
is the data, bound to the circle.
Instead of color, in this example the function passes an object (packageName attribute of d
).
Each object gets own unique color assigned to it, according to selected color scale:
fill = d3.scale.category20c();
如果您对使用的着色标准(packageName)感到满意,您可以更改调色板(颜色刻度):
如果要更改着色标准,则需要更改返回部分,将其替换为颜色值作为数据 d
的函数。
If you are happy with used criteria for coloring (packageName) and all you need is to change colors, you could change the palette (color scale):
https://github.com/mbostock/d3/wiki/Ordinal-Scales
if you want to change the coloring criteria, then you need to change the return part, replacing it with color value as a function of data d
.
在这里您可以找到D3颜色构造函数:
Here you can find D3 color constructors:
https://github.com/mbostock/d3/wiki/Colors
这篇关于d3圆圈:设置圆圈颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!