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

Here is an example of the pack layout in d3js:

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

Here is another example of the pack layout with colors:

enter image description here

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

1

1 Answer

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.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like