Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Selecting a Year on a Line Chart

Public visualization

Selecting a Year on a Line Chart

0 stars0🌍 Public
PPhilRG
Last edited May 17, 2020
Created on May 17, 2020

A line chart displays population over time for multiple regions, with a vertical line marking a selected year. Users can hover anywhere on the chart to update the selection, which triggers a re-render of the visualization. The code uses D3 v5’s `scaleTime`, `scaleLinear`, `axisBottom`, `axisLeft`, and `line` with `curveBasis` to draw the chart, while a `mouse` event on a transparent `rect` calls `setSelectedYear` to change the year. The data comes from UN population estimates and medium-variant projections, loaded via `csv` and processed with `nest`, `descending`, and a custom `melt` function. The rendering is SVG-based, with a color legend created by `colorLegend` and axes styled via CSS.

AI-generated description

Comments

Sign in to join the discussion.

MIT Licensed