Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Color and Size legends

Public visualization

Color and Size legends

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

Comments

Sign in to join the discussion.

MIT Licensed