Published
Edited
Oct 16, 2021
Insert cell
# Basics
Insert cell
x = d3.scaleUtc()
.domain(d3.extent(data, d => d.date))
.range([margin.left, width - margin.right])
Insert cell
y = d3.scaleLinear()
.domain([0, d3.max(data, d => d.numconf)])
.range([height - margin.bottom, margin.top])
Insert cell
arc = d3.arc()
.innerRadius(210)
.outerRadius(310)
.startAngle(([startAngle, endAngle]) => startAngle)
.endAngle(([startAngle, endAngle]) => endAngle)
Insert cell
arc([Math.PI / 2, Math.PI])
Insert cell
viewof n = {
const form = html`<form style="font: 12px var(--sans-serif); display: flex; align-items: center; min-height: 33px;">
<label style="display: block;">
<input name="input" type="range" min="1" max="50" value="12" step="1" style="width: 180px;">
n = <output name="output"></output>
</label>
</form>`;
form.oninput = () => form.output.value = form.value = form.input.valueAsNumber;
form.oninput();
return form;
}
Insert cell
html`<svg viewBox="-320 -320 640 640" style="max-width: 640px;">
${Array.from({length: n}, (_, i) => svg`<path stroke="black" fill="${d3.interpolateRainbow(i / n)}" d="${arc([i / n * 2 * Math.PI, (i + 1) / n * 2 * Math.PI])}"></path>`)}
</svg>`
Insert cell
pieArcData = d3.pie()
.value(d => d.numconf)
(data)
Insert cell
vl = require('@observablehq/vega-lite')
Insert cell
margin = ({top: 20, right: 0, bottom: 0, left: 150})
Insert cell
height = 240
Insert cell
xAxis = (g, x) => g
.attr("transform", `translate(0,${margin.top})`)
.call(d3.axisTop(x).ticks(width / 80, "%"))
.call(g => (g.selection ? g.selection() : g).select(".domain").remove())
Insert cell
yAxis = (g, y) => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y).tickSizeOuter(0))
Insert cell
data = FileAttachment("covid19-data@1.csv").csv()
Insert cell
d3 = require("d3@6")
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