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

前端 未结 5 1413
小蘑菇
小蘑菇 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 12:05

    Your problem is that group is not defined for your data. As a result, all of your nodes are colored for group 'undefined'. Your circles are defined for the data in force.nodes(), which have the attributes index name px py weight x and y. group is only defined for the links, which never have color applied to them.

    As it currently stands, there also isn't a clear way to determine what color a node should be. What happens if more than one link connects to a node, and these links are in different groups?

提交回复
热议问题