Skip to main content
100%

Color and size legends

✓ Published0🌍 Public
Aarieltonglet
Last edited Oct 14, 2019
Created on Oct 1, 2019

Two adjacent legends illustrate how to construct reusable D3 legend components. A color legend uses `d3.scaleOrdinal` with fruit types mapped to red, yellow, orange, and green, rendering circles with corresponding fills and text labels. A size legend uses `d3.scaleSqrt` to map values 0–10 to circle radii, with ticks generated via `sizeScale.ticks` and positioned by cumulative spacing. Both legends are appended as SVG groups, with enter/merge/exit selections managing dynamic updates.

AI-generated description
MIT Licensed

Similar vizzes