Color and Size legends
✓ Published0🌍 Public
This example builds two custom legends in D3 v5: a color legend mapping fruit names to ordinal colors, and a size legend using a square-root scale. The legends are rendered as SVG groups with circles and text labels. The color legend uses `scaleOrdinal` with a hardcoded domain, while the size legend uses `scaleSqrt` with ticks generated via `sizeScale.ticks()`. Both legends are positioned manually and styled with CSS classes, demonstrating reusable legend components through the `selection.call()` pattern.
AI-generated descriptionMIT Licensed