Color and Size Legends
✓ Published0🌍 Public
Fframptonb
Last edited Feb 18, 2023
Created on Feb 17, 2023
This example demonstrates how to build both a color legend and a size legend using D3.js v5. The color legend maps ordinal categories (Apple, Lemon, Lime, Orange) to distinct colors via `scaleOrdinal`, while the size legend uses `scaleSqrt` to represent numerical values from 0 to 10 as circle radii. Both legends implement a general update pattern with `selection.merge()` for enter and exit transitions, rendering circles and text labels in SVG. The ticks for the size legend are generated using `sizeScale.ticks()`, with all elements styled via CSS classes.
AI-generated descriptionCreating a color legend and a Size Legend with D3.js (based on a tutorial by Curran Kelleher)
<iframe width="560" height="315" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>MIT Licensed