Skip to main content
Public

Share visualization

Loading preview…

Sequential Color Legend in D3

vizhub.com

Shared links may look like this on X, LinkedIn, Slack, and Discord.

Before sharing, review the publishing checklist.

Choose how to deliver this visualization

LinkedIn caption

LinkedIn may not keep text supplied by the share sheet. Copy the caption and paste it into the post if needed. You can tag the VizHub company page when posting.

More options

Embed on a websiteCopy iframe embed code
Download & exportPNG, HTML, source ZIP

Sequential Color Legend in D3

0
AAlark Joshi
Last edited Mar 5, 2026
Created on Sep 27, 2022
Forked from HTML Starter

This example demonstrates how to generate a sequential color legend using Susie Lu’s d3-legend library. It renders a small SVG with a legend title and five color cells, mapping a domain of seven distance values to a red interpolator via `d3.scaleSequential` and `d3.interpolateReds`. The legend is created with `d3.legendColor()`, configured with a title and scale, and attached to an SVG group using a standard D3 selection and `.call()`. The chart uses D3 v7 and d3-legend v2.25.6, rendering entirely as inline SVG.

AI-generated description

Demonstration of the use of Susie Lu's d3-legend to display a color legend that uses a sequential color scale.

Comments

Sign in to join the discussion.

MIT Licensed