Published
Edited
Jul 15, 2020
Insert cell
Insert cell
{
const svg = d3.create("svg")
.attr("viewBox", [-10, -20, width, height]);
const l = 30;
svg.selectAll("path")
.data(trends)
.join("path")
.attr("d", `M 0 0 L ${l} 0`)
.attr("transform", (d, i) => `translate(0, ${20*i}) rotate(${scale(d[1] / d[0])}, ${l / 2}, 0)`)
.attr("stroke-width", 4)
.attr("stroke", (_, i) => color(i));
return svg.node();
}
Insert cell
color = d3.scaleSequential()
.domain([-2, 6])
.interpolator(d3.interpolateRdBu);
Insert cell
scale = d3.scaleLinear()
.domain([maxVal, 0])
.range([-60, 60]);
Insert cell
maxVal = d3.max(trends, d => d[1] / d[0])
Insert cell
trends.map(d => d[1] / d[0])
Insert cell
Insert cell
height = 120
Insert cell
d3 = require("d3@5")
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