Skip to main content
100%

Color and Size Legends

✓ Published0🌍 Public
Pprincit
Last edited Mar 30, 2020
Created on Mar 28, 2020

This example demonstrates how color legends and size legends are constructed using D3 v5’s ordinal and square-root scales. A colorLegend component renders colored circles for fruit categories, while a sizeLegend maps numeric tick values to circle radii. Both legends are built with data-bound SVG groups, using `selection.enter()` and `selection.merge()` for updates, and `scaleOrdinal` and `scaleSqrt` for encoding. The code also employs `sizeScale.ticks()` to generate evenly spaced legend entries, with text labels offset from each circle.

AI-generated description
MIT Licensed

Similar vizzes