I am accessing the following sample page on observablehq. Force directed graph
At the moment the page colors node based on group.
I am struggling to do the following:
- colorfill (with a specific colour) a node (or all nodes) based on a value of the node
Any help?
Thanks
Advertisement
Answer
The group accessor allows you to access each node, in the example it is accessing the group
property of the node: nodeGroup: d => d.group
.
The example also uses a ordinal scale, if you want to use continuous values from your nodes you could fork the example (or copy the whole function) and change the d3.scaleOrdinal to something like d3.scaleLinear