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
SSybil Jas
Last edited Feb 23, 2020
Created on Feb 23, 2020
Forked from HTML Starter

This example demonstrates how to build custom legends for both ordinal color scales and quantitative size scales using D3 v5 within a React application. The color legend maps fruit categories (apple, lemon, lime, orange) to corresponding colors, while the size legend uses `scaleSqrt` to represent numeric values from 0 to 10 with proportional circle radii. Both legends employ the general update pattern with data joins on SVG groups, using `selection.enter()`, `merge()`, and `exit()` to handle dynamic updates. The code also showcases `sizeScale.ticks()` to generate clean tick values for the size legend.

AI-generated description

A bare minimum HTML page.

See also React Starter.

Comments

Sign in to join the discussion.

MIT Licensed