d3圆圈:设置圆圈颜色 [英] d3 circle pack: setting circle colors

查看:1249
本文介绍了d3圆圈:设置圆圈颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 http://mbostock.github.com/d3/ex/ bubble.html
,但颜色已更改。

I try to use http://mbostock.github.com/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.com/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):
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颜色构造函数:

https://github.com/mbostock/d3/wiki/Colors

Here you can find D3 color constructors:
https://github.com/mbostock/d3/wiki/Colors

这篇关于d3圆圈:设置圆圈颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆