how to move from d3.group to a format that works for a sunburst chart?

You can compute a d3.hierarchy directly from d3.rollup:

rollup = d3.rollup(sovereign_projects.slice(1), d => d.length, d => d["Status"], d => d["Country"],  d => d["Sector"])
root = d3.hierarchy(rollup)

The problem is that D3 Zoomable Sunburst example uses d => d.value as the value accessor for computing the value of each node. If you use d3.rollup as input, then the leaf nodes are [key, value] entries, and so you need to say instead:

root = d3.hierarchy(rollup).sum(([, value]) => value)

There are a few other changes that need to be adapted from that example. Here’s a working fork with your data:

And here’s what I changed:

4 Likes