Skip to main content
100%

Multi-line graph 4 with v4: Toggle

✓ Published0🌍 Public
Dd3noob
Last edited Nov 7, 2016
Created on Nov 5, 2016

This interactive multi-line chart displays monthly stock prices for three companies (MSFT, AMZN, IBM) from 2000 onward, with a clickable legend that toggles each line’s visibility. Using D3 v4, the code parses CSV data with `d3.csv`, nests records by symbol, and renders SVG paths via `d3.line` and `d3.scaleTime`/`d3.scaleLinear`. Clicking a legend text triggers a 100ms `transition` on the corresponding line’s opacity, dynamically showing or hiding it. The legend colors are assigned with `d3.scaleOrdinal` and `d3.schemeCategory10`.

AI-generated description

This is a derivative of the simple d3.js graph in v4 used as an example in the book D3 Tips and Tricks v4. The stock data was sourced from Mike Bostock's small multiples example.

It is the fourth graph in a series that is building a multi-line graph that incorperates an automatically developed legend and a system that can toggle the lines off and on as desired.

This version is demonstrating the ability to toggle the lines off and on by clicking on the appropriate legend text.

The graph should be taken in context with the text of the book which can be downloaded for free from Leanpub.

Similar vizzes