Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Color and Sized Legends with D3.js

Public visualization

Viewing a saved revision (read-only)

8aea4d4a13b64a55b303bd6935e7bd9b

Color and Sized Legends with D3.js

0 stars0🌍 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