Skip to main content
100%

color and size legends

✓ Published0🌍 Public
Zzenoe
Last edited Oct 5, 2021
Created on Oct 5, 2021

Two legends demonstrate how to encode data with color and size in D3 v5. The color legend maps fruit categories to distinct colors using `scaleOrdinal`, while the size legend uses `scaleSqrt` to represent numeric values with scaled circle radii. Each legend is built as a reusable component that appends SVG groups with circles and text labels, spacing them vertically and offsetting text from the markers. The code uses selection joins to update the legends’ marks and labels, with `enter()` handling new elements.

AI-generated description
MIT Licensed

Similar vizzes