D3.js force directed graph, each group different color?

前端 未结 5 1402
小蘑菇
小蘑菇 2021-01-12 11:27

I\'ve made a force directed graph with d3.js plugin, and I wanna color the nodes and the labels with the different color according to group which they belong.

I\'ve

5条回答
  •  再見小時候
    2021-01-12 11:51

    I think you need to change the style attribute of the circle, not the g element.

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

    Edit: The group property in the data must also be changed integers, or cast later.

提交回复
热议问题