Skip to main content
100%

Multi-line graph 3 with v5: Legend

✓ Published0🌍 Public
Dd3noob
Last edited Sep 15, 2020
Created on Sep 15, 2020

This example shows a multi-line chart tracking monthly stock prices for three companies (MSFT, AMZN, IBM) from 2000 to 2010, with a color-coded legend placed below the x-axis. Using D3 v5, it nests the CSV data by symbol, draws each series as an SVG path, and assigns colors via `d3.scaleOrdinal` with `d3.schemeCategory10`. The legend labels are dynamically positioned and colored to match each line, and axes are generated with `d3.axisBottom` and `d3.axisLeft`.

AI-generated description

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

It is the third 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 addition of a legend to the graph.

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/d3noob/'>d3noob</a>'s block: <a href='http://bl.ocks.org/d3noob/7bf95c7ac092db2fe31a979b926b91b8'>Multi-line graph 3 with v5: Legend</a>

mit Licensed

Similar vizzes