我尝试使用 mbostock.github/d3/ex/ bubble.html ,但颜色已更改。
I try to use mbostock.github/d3/ex/bubble.html but 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)感到满意,您可以更改调色板(颜色刻度): https:// github/mbostock/d3/wiki/Ordinal-Scales 如果要更改着色标准,则需要更改返回部分,将其替换为颜色值作为数据 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): github/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颜色构造函数: github/mbostock/d3/wiki/Colors
Here you can find D3 color constructors: github/mbostock/d3/wiki/Colors
更多推荐
d3圆圈:设置圆圈颜色
发布评论