Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Fork of Color and Size Legends2

Public visualization

Fork of Color and Size Legends2

0 stars0🌍 Public
Jjlspangl
Last edited Oct 13, 2021
Created on Oct 13, 2021

This example demonstrates two reusable legend components for D3 v5: a color legend using an ordinal scale mapping fruit names to colors, and a size legend using a square-root scale with five ticks. Both render as SVG groups with circles and text labels, positioned via transforms. The colorLegend component encodes categorical data with colored circles, while the sizeLegend uses scaled circle radii and offsets text based on each value’s radius. The code imports `scaleOrdinal` and `scaleSqrt` from D3, and uses selection joins to update or remove legend items dynamically.

AI-generated description

Comments

Sign in to join the discussion.

MIT Licensed