Public
Edited
Aug 22, 2023
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require("d3-hierarchy@7")
Insert cell
hierarchy = d3
.stratify()
.id(d => d.name)
.parentId(d => d.parent)(data)
Insert cell
Insert cell
function hierarchyToJson(root) {
const obj = { name: root.id };
if (root.children) obj.children = root.children.map(hierarchyToJson);
if (root.data && root.data.value) obj.value = root.data.value;
return obj;
}
Insert cell
json = hierarchyToJson(hierarchy)
Insert cell
Insert cell
import { chart } with { json as data } from "@d3/zoomable-sunburst@353"
Insert cell
chart
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more