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
TTomoyukiEguchi
Last edited Jan 18, 2021
Created on Jan 10, 2021

This example demonstrates two reusable legend components for D3.js v5 visualizations: a color legend using a categorical `scaleOrdinal` and a size legend using a `scaleSqrt`. The color legend maps fruit categories to distinct colors with circular swatches, while the size legend renders circles whose radii correspond to numeric values, filtered to exclude zero. Both legends use SVG groups and update joins to manage entering and exiting elements. The code defines reusable `colorLegend` and `sizeLegend` functions, invoked via the `.call()` method with custom spacing, text offsets, and tick counts.

AI-generated description

Comments

Sign in to join the discussion.

MIT Licensed