Published
Edited
Feb 16, 2022
Insert cell
Insert cell
d3 = require("d3", "d3-scale", "d3-axis", "d3-selection")
Insert cell
_ = require("lodash")
Insert cell
width = 800
Insert cell
height = 600
Insert cell
margin = ({top: 50, right: 50, bottom: 50, left: 50})
Insert cell
Insert cell
Insert cell
data = FileAttachment("imdbTop250.csv").csv({typed: true})
Insert cell
genres = _.uniq(data.filter(d => d.Ranking <= 100).flatMap(d => d.Genre.split(", ")))
Insert cell
Insert cell
Insert cell
x = d3.scaleLinear()
.domain([0, 100])
.range([margin.left, width - margin.right])
Insert cell
y = d3.scaleLinear()
.domain([6, 10])
.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(${width - margin.right}, 0)`)
.call(d3.axisLeft(y).tickSize(width - margin.left - margin.right))
.call(g => g.select(".domain").remove())
.call(g => g.selectAll(".tick:not(:first-of-type) line")
.attr("stroke-opacity", 0.5)
.attr("stroke-dasharray", "2,2"))
.call(g => g.selectAll(".tick:first-of-type text").remove());
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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