Public
Edited
Mar 22, 2023
Insert cell
Insert cell
chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);

svg.append("g")
.attr("fill", "none")
.attr("stroke-width", 1.5)
.attr("stroke-opacity", 0.4)
.selectAll("path")
.data(nodes_parra_f)
.join("path")
.attr("stroke", '#ccc')
.attr("d", d => line(d3.cross(keys, [d], (key, d) => [key, d[key]])))
.append("title")
.text(d => d.name);

svg.append("g")
.selectAll("g")
.data(keys)
.join("g")
.attr("transform", d => `translate(0,${y(d)})`)
.each(function(d) { d3.select(this).call(d3.axisBottom(x.get(d))); })
.call(g => g.append("text")
.attr("x", margin.left)
.attr("y", -6)
.attr("text-anchor", "start")
.attr("fill", "currentColor")
.text(d => d))
.call(g => g.selectAll("text")
.clone(true).lower()
.attr("fill", "none")
.attr("stroke-width", 5)
.attr("stroke-linejoin", "round")
.attr("stroke", "white"));

return svg.node();
}
Insert cell
nodes_parra_f = FileAttachment("nodes_parra_f.json").json()
Insert cell
data = FileAttachment("cars.csv").csv({typed: true})
Insert cell
keys=Object.keys(nodes_parra_f[0]).filter(d=>d!=="id"&d!=='name')
Insert cell
x = new Map(Array.from(keys, key => [key, d3.scaleLinear(d3.extent(nodes_parra_f, d => d[key]), [margin.left, width - margin.right])]))
Insert cell
y = d3.scalePoint(keys, [margin.top, height - margin.bottom])
Insert cell
line = d3.line()
.defined(([, value]) => value != null)
.x(([key, value]) => x.get(key)(value))
.y(([key]) => y(key))
Insert cell
margin = ({top: 20, right: 10, bottom: 20, left: 10})
Insert cell
height = keys.length * 120
Insert cell
d3 = require("d3@6")
Insert cell
import {legend as Legend} from "@d3/color-legend"
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