Published
Edited
Nov 13, 2020
Insert cell
Insert cell
chart = {
const svg = d3
.create("svg")
.attr("viewBox", [-width / 2, -height / 2, width, height])
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round");

svg
.append("path")
.attr("fill", "pink")
.attr("stroke", "none")
// .attr("stroke-width", 1.5)
.attr("d", line.radius(d => y(d.avg))(data));

return svg.node();
}
Insert cell
width = 954
Insert cell
height = width
Insert cell
margin = 100
Insert cell
innerRadius = width / 10
Insert cell
outerRadius = width / 2 - margin
Insert cell
x = d3.scaleLinear()
.domain([1900,2020])
.range([0, 2 * Math.PI])
Insert cell
y = d3.scaleLinear()
.domain([0,360])
.range([innerRadius, outerRadius])
Insert cell
line = d3
.lineRadial()
.curve(d3.curveBasisClosed)
.angle(d => x(d.year))
Insert cell
area = d3.areaRadial()
.curve(d3.curveLinearClosed)
.angle(d => x(d.date))
Insert cell
rawdata = d3.csvParse(await FileAttachment("sfo-temperature.csv").text(), d3.autoType)
Insert cell
data = {
let dataset = [];
let dataPt;

let span = 120;
let petals = 6;

for (let i = 1900; i < 1900 + span; i++) {
if (i % (span / petals) == 0) {
dataPt = 0;
} else {
dataPt = Math.floor(Math.random() * 180) + 180;
}

dataset.push({
year: i,
//date:new Date(Date.UTC(i, Math.floor(Math.random()*12), Math.floor(Math.random()*30)))
avg: dataPt
});
}

return dataset;
}
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