Skip to main content
100%

Multi-line graph 4: Toggle

✓ Published0🌍 Public
663anp3ca
Last edited Oct 16, 2018
Created on Oct 16, 2018

This multi-line graph displays monthly stock prices for multiple companies over time, with each line assigned a unique color via D3's category10 scale. The data is loaded from a CSV file, nested by stock symbol, and rendered as separate SVG paths using D3’s time scale for dates and linear scale for prices. A legend with clickable text labels allows users to toggle individual lines on and off; clicking a legend entry fades the corresponding line to an opacity of zero or restores it to full opacity with a 100ms transition. The chart includes axes and a dynamic color assignment, with the toggle functionality demonstrated as the fourth iteration in a series focused on building interactive multi-line graphs.

AI-generated description

This is a derivative of the simple d3.js graph used as an example in the book D3 Tips and Tricks. 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.

forked from <a href='http://bl.ocks.org/cse4qf/'>cse4qf</a>'s block: <a href='http://bl.ocks.org/cse4qf/9a171be6f1d9dd9e58c8789a91691edf'>Multi-line graph 4: Toggle</a>

mit Licensed

Similar vizzes