Skip to main content
100%

Color and Size legends

✓ Published0🌍 Public
LLongYuu
Last edited Nov 28, 2020
Created on Nov 28, 2020

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 description
MIT Licensed

Similar vizzes