Public
Edited
Jun 18, 2023
Insert cell
Insert cell
am5 = require("https://amcharts.com/lib/5/index.js").catch(() => window.am5)
Insert cell
am5flow = {
await am5;
return await require("https://cdn.amcharts.com/lib/5/flow.js").catch(() => window.am5flow);
}
Insert cell
am5themes_Animated = {
await am5;
return await require("https://cdn.amcharts.com/lib/5/themes/Animated.js").catch(() => window.am5themes_Animated);
}
Insert cell
<div id="chartdiv"></div>

<style>
#chartdiv {
width: 100%;
height: 600px;
</style>
Insert cell
data = {

// Set data
// https://www.amcharts.com/docs/v5/charts/flow-charts/#Setting_data

let exampleData = [
{ "from": "Lindsay", "to": "Bob", "value": 20 },
{ "from": "Lindsay", "to": "Jamie", "value": 10 },
{ "from": "Lindsay", "to": "Rebecca", "value": 5 },
{ "from": "Lindsay", "to": "Jess", "value": 6},
{ "from": "Bob", "to": "Lindsay", "value": 9 },
]

return exampleData;
}
Insert cell
// Create root element
// https://www.amcharts.com/docs/v5/getting-started/#Root_element
root = am5.Root.new("chartdiv");
Insert cell
{
await am5
return await am5.ready(function() {

// Set themes
// https://www.amcharts.com/docs/v5/concepts/themes/
root.setThemes([
am5themes_Animated.new(root)
]);


// Create series
// https://www.amcharts.com/docs/v5/charts/flow-charts/
var series = root.container.children.push(am5flow.ChordDirected.new(root, {
startAngle: 80,
padAngle: 1,
linkHeadRadius: undefined,
sourceIdField: "from",
targetIdField: "to",
valueField: "value"
}));

series.nodes.labels.template.setAll({
textType: "radial",
centerX: 0,
fontSize: 9
});

series.links.template.set("fillStyle", "source");

// Set data
// https://www.amcharts.com/docs/v5/charts/flow-charts/#Setting_data
series.data.setAll(data);

// Make stuff animate on load
series.appear(1000, 100);

}); // end am5.ready()

}
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