Published
Edited
Sep 16, 2020
2 forks
3 stars
Insert cell
Insert cell
chart = {
const svg = d3.create('svg')
.attr('viewBox', [-width/2, -height/2-marginTop, width, height]);

svg.selectAll('path')
.data(pieData)
.join('path')
.attr('d', arc)
.attr('fill', d => color(d.data.key))
.attr('stroke', 'white')
.style('stroke-width', 2);
return svg.node();
}
Insert cell
arc = d3.arc()
.outerRadius(radius)
.innerRadius(radius - thickness)
Insert cell
pieData = pie(d3.entries(data))
Insert cell
pie = d3.pie()
.value(d => d.value)
.sort(null)
.startAngle(-anglesRange)
.endAngle(anglesRange);
Insert cell
anglesRange = 0.5 * Math.PI
Insert cell
thickness = 120
Insert cell
radius = 150
Insert cell
marginTop = 30
Insert cell
height = 300
Insert cell
color = d3.scaleOrdinal()
.domain(data)
.range(d3.schemePastel1)
Insert cell
data = ({a: 10, b: 50, c: 15, d: 20, e: 5})
Insert cell
d3 = require("d3@5")
Insert cell
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