Public
Edited
Oct 26, 2023
3 forks
1 star
Insert cell
Insert cell
Insert cell
chart = {
const data = [1, 1, 2, 3, 5, 8, 13, 21];
const pie1 = d3.pie().padAngle(0.03); // fixed pad angle (bad)
const pie2 = d3.pie().padAngle(padAngle); // adjusted pad angle (good)
const arc = d3.arc().innerRadius(innerRadius).outerRadius(outerRadius);

const svg = d3.create("svg")
.attr("viewBox", [0, -height / 2, width, height]);

const g = svg.selectAll("g")
.data(() => [pie1(data), pie2(data)])
.join("g")
.attr("fill", (d, i) => ["brown", "steelblue"][i])
.attr("transform", (d, i) => `translate(${width / 2 * (i + 0.5)})`);

g.append("g")
.attr("fill", "none")
.attr("stroke", "#777")
.selectAll("path")
.data(arcs => arcs)
.join("path")
.attr("d", arc.padAngle(0));

g.append("g")
.attr("stroke", "#000")
.attr("stroke-width", "1.5px")
.attr("stroke-linejoin", "round")
.selectAll("path")
.data(arcs => arcs)
.join("path")
.attr("d", arc.padAngle(padAngle));

return svg.node();
}
Insert cell
Insert cell
width = 960
Insert cell
height = 500
Insert cell
outerRadius = height / 2 - 30
Insert cell
innerRadius = outerRadius / 3
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more