Published
Edited
Dec 7, 2020
Importers
Insert cell
Insert cell
Insert cell
gapminder2000 = gapminder // data to use in your chart, filtered on 2000 and sorted by fertility
.filter(d => d.year === 2000)
.sort((a, b) => b.pop - a.pop)
.slice(0, 50)
.sort((a, b) => b.fertility - a.fertility)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
//y =... create the d3 scale for the y axis here
y = d3.scaleBand()
.domain(gapminder2000.map(d => d.country))
.range([margin.top, chartHeight - margin.bottom])
.padding(0.2)
Insert cell
yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y).tickSize(0))
.call(g => g.select(".domain").remove())
Insert cell
d3.create("g").call(xAxis)
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${chartHeight - margin.bottom})`)
.call(d3.axisTop(x).tickSizeOuter(0).tickSizeInner(chartHeight - margin.bottom - margin.top))
.call(g => {
g.select(".domain").remove();
g.selectAll(".tick line").attr("stroke", "white").attr("stroke-width", 0.5)
})
Insert cell
Insert cell
Insert cell
xAxisScatter = g => g
.attr("transform", `translate(0,${chartHeight - margin.bottom})`)
.call(d3.axisBottom(x).tickSizeOuter(0))
.call(g => {
g.select(".domain").remove();
})
Insert cell
yAxisScatter = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(yScatter))
.call(g => g.select(".domain").remove())
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