Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. D3
  3. d3-legend

d3-legend

Apache-2.0JavaScriptv2.25.5

A reusable D3.js legend component for color, size, and symbol scales in SVG visualizations.

Visit WebsiteGitHubGitHub
724 stars103 forks0 contributors

What is d3-legend?

d3-legend is a reusable legend component for D3.js that generates legends for color, size, and symbol scales in SVG-based data visualizations. It solves the problem of manually creating and styling legends, providing a consistent, configurable way to explain visual encodings in charts and maps.

Target Audience

Data visualization developers using D3.js who need to add professional, customizable legends to their SVG charts, dashboards, or interactive maps.

Value Proposition

Developers choose d3-legend because it integrates seamlessly with D3 scales, reduces boilerplate code for legend creation, and offers flexible styling through CSS classes, all while following D3's familiar API patterns.

Overview

A reusable d3 legend component.

Use Cases

Best For

  • Adding color legends to choropleth maps or heatmaps
  • Creating size legends for bubble charts or scatter plots
  • Displaying symbol legends for categorical data in visualizations
  • Building interactive dashboards with D3.js that require clear scale explanations
  • Styling legends consistently across multiple charts in a project
  • Quickly prototyping data visualizations with professional-looking legends

Not Ideal For

  • Projects built with React, Vue, or other modern frameworks that prefer integrated, declarative charting components
  • Applications requiring advanced legend interactions like click-to-filter or real-time animations without manual D3 updates
  • Teams needing ongoing feature development or active community support, as the library is in maintenance mode with no new features

Pros & Cons

Pros

Seamless D3 Integration

Directly works with D3 scales and follows D3's data-binding patterns, making it a natural extension for existing D3 visualizations without extra abstractions.

CSS Styling Flexibility

Supports CSS classes via methods like .useClass(true), allowing easy customization to match project designs without modifying core JavaScript code.

Reduces Boilerplate Code

Eliminates the need to manually draw and position SVG legend elements, saving development time for common legend types like color or size scales.

Stable and Mature

The library is in maintenance mode, ensuring a stable API with minimal breaking changes, which is reliable for production environments.

Cons

Maintenance Mode Limitations

No new features or updates are planned, as stated in the README, which could lead to compatibility issues with future D3 versions or missing modern visualization needs.

D3 Ecosystem Lock-in

Heavily dependent on D3.js and SVG; if a project migrates away from D3, the legend component becomes obsolete or requires significant reimplementation.

Limited Legend Types

Only covers color, size, and symbol scales, lacking built-in support for other encodings like opacity or complex interactive legends without custom code.

Frequently Asked Questions

Quick Stats

Stars724
Forks103
Contributors0
Open Issues10
Last commit1 year ago
CreatedSince 2015

Tags

#graphics#svg#frontend#data-visualization#d3-module#javascript#charts#d3

Built With

d
d3
G
Grunt
J
JavaScript
S
SVG
n
npm

Links & Resources

Website

Included in

D35.3k
Auto-fetched 1 day ago

Related Projects

Textures.jsTextures.js

Textures.js is a JavaScript library for creating SVG patterns

Stars6,079
Forks220
Last commit3 years ago
crossfiltercrossfilter

Fast n-dimensional filtering and grouping of records.

Stars1,757
Forks190
Last commit2 years ago
d3-annotationd3-annotation

Use d3-annotation with built-in annotation types, or extend it to make custom annotations. It is made for d3-v4 in SVG.

Stars762
Forks73
Last commit3 years ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub