Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you color each circle in the D3 circle pack layout

Here is an example of the pack layout in d3js:

http://bl.ocks.org/4063530

Is it possible to control the colors of the individual cirles?

Here is another example of the pack layout with colors:

http://bl.ocks.org/4063269

enter image description here

Can you help me understand how the colors are assigned to the bubbles in the second chart?

like image 963
nilanjan Avatar asked Dec 13 '25 05:12

nilanjan


1 Answers

You can just add the attribute fill to change the color:

node.append("circle")
      .attr("r", function(d) { return d.r; })
      .style("fill", function(d){ return d.color; });

In the example above, suppose your data contains a color field.

like image 79
Christopher Chiche Avatar answered Dec 14 '25 18:12

Christopher Chiche



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!