🌍 Public
Viewing a saved revision (read-only)
7633b54372ab4703ad2ab0ab4236bfd4
Color and size legends with D3.js!
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 descriptionA bare minimum HTML page.
See also React Starter.