Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Color and size legends with D3.js!

Public visualization

Color and size legends with D3.js!

0 stars0🌍 Public
Fforcox43
Last edited Jul 16, 2020
Created on Jul 16, 2020

This example demonstrates how to build custom color and size legends using D3.js v5 in a React application. It shows an ordinal color scale mapping fruit names to distinct colors, alongside a square-root size scale with five ticks rendered as proportionally sized circles. The code defines reusable legend components that use selection joins with `merge()` and `exit().remove()` to manage SVG groups dynamically. Both legends render as SVG, with circles and text positioned using transform attributes and spacing parameters.

AI-generated description

A bare minimum HTML page.

See also React Starter.

Comments

Sign in to join the discussion.

MIT Licensed