Skip to main content
100%

Color and Sized Legends with D3.js

✓ Published0🌍 Public
Yyouer
Last edited Mar 22, 2020
Created on Mar 22, 2020

This example demonstrates how to build a color legend with D3.js, using a categorical scale to map named domains like “apple” and “lemon” to red and yellow circles. The code leverages `scaleOrdinal`, `selection.merge`, and custom legend functions to position groups with spacing, adding text labels offset from each circle. It renders as SVG with a static dataset defined inline, showing the legend’s interactivity through enter, update, and exit selections. The visualization also includes sample population data from a CSV file, though it is not actively displayed in the main legend.

AI-generated description
MIT Licensed

Similar vizzes