Published
Edited
Dec 7, 2020
2 forks
Insert cell
Insert cell
Insert cell
gapminderData = (await require('vega-datasets'))["gapminder.json"]()
Insert cell
Insert cell
linesDataByCountry = Array.from(d3.group(gapminderData, d => d.country).values())
Insert cell
Insert cell
height = 300;
Insert cell
margin = ({top: 30, right: 30, bottom: 30, left: 30})
Insert cell
Insert cell
lineGenerator = d3.line()
.x(d => xScale(d.year))
.y(d => yScale(d.pop));
Insert cell
Insert cell
lineGenerator(linesDataByCountry[0])
Insert cell
Insert cell
xScale = d3.scaleLinear()
// .domain(todo)
// .range(todo);
Insert cell
yScale = d3.scaleLinear()
// .domain(todo)
// .range(todo);
Insert cell
Insert cell
linechart = {
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height);
/*
todo:
- use the d3 data join to add a "path" element for every country (dataByCountry) to the svg.
- add a "d" attribute to the "path" elements and use the lineGenerator to generate the path commands
- add these attributes to the "path" elements: stroke is "lightgrey"; stroke-width is 2; fill is "none"
- add axes and anything else to complete the chart as described in the task description
*/
return svg.node();
}
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