Published
Edited
May 23, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
margin = ({top: 10, bottom: 40, left: 50, right: 10})
Insert cell
visWidth = 600 - margin.left - margin.right
Insert cell
visHeight = 400 - margin.top - margin.bottom
Insert cell
Insert cell
maxScore = d3.max(data, d => d.score)
Insert cell
scoreScale = d3.scaleLinear()
.domain([0, maxScore])
.nice() // make the domain start and end on round values
// changed from [0, visWidth] to [visHeight, 0]
.range([visHeight, 0])
Insert cell
names = data.map(d => d.name)
Insert cell
// turn nameScale into a scalePoint
nameScale = d3.scalePoint()
.domain(names)
// changed from [0, visHeight] to [0, visWidth]
.range([0, visWidth])
.padding(0.2)
Insert cell
Insert cell
// changed scoreScale to nameScale
xAxis = d3.axisBottom(nameScale)
Insert cell
// changed nameScale to scoreScale
yAxis = d3.axisLeft(scoreScale)
Insert cell
Insert cell
Insert cell
Insert cell
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