Public
Edited
May 31, 2023
Insert cell
Insert cell
Insert cell
Insert cell
height = 400
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dataScatter = {
const raw = await FileAttachment("penguins.csv").csv({typed: true});
return raw.map(d=> ({...d, xValue: d.flipper_length_mm, yValue: d.body_mass_g}))
}
Insert cell
outerRadius = height/2
Insert cell
size = 600
Insert cell
x = data => d3.scaleUtc()
.domain(d3.extent(data, d => d.xValue)).nice()
.range([margin.left, width - margin.right])
Insert cell
xRadial = data => d3.scaleUtc()
.domain(d3.extent(data, d => d.xValue))
.range([0, 2 * Math.PI])
Insert cell
yRadial = data => d3.scaleLinear()
.domain(d3.extent(data, d => d.yValue)).nice()
.range([innerRadius, outerRadius])
Insert cell
y = data =>d3.scaleLinear()
.domain(d3.extent(data, d => d.yValue)).nice()
.range([height - margin.bottom, margin.top])
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x))
Insert cell
yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y))
Insert cell
margin = ({top: 25, right: 20, bottom: 35, left: 40})
Insert cell
line = d3.line()
// .defined(d=>d.xValue)
// .curve(curve)
.x(d=>x(dataLine)(d.xValue))
.y(d=>y(dataLine)(d.yValue))
Insert cell
Insert cell
Insert cell
dataLine = aapl.map(d => ({...d, xValue: d.date, yValue: d.close}))
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