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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more