Skip to main content
100%

Color and size legends

✓ Published0🌍 Public
PPiotr Paszek
Last edited Apr 25, 2021
Created on Apr 25, 2021

This example demonstrates reusable D3 color and size legend components, rendered as SVG within a 960×500 viewport. The color legend uses a `scaleOrdinal` with categorical fruit domains mapped to red, yellow, green, and orange, while the size legend applies a `scaleSqrt` with tick marks generated via `sizeScale.ticks()`. Both legends employ D3’s data join pattern (`selectAll`, `enter`, `merge`) to append circle and text elements per tick, with spacing and text offsets configured through component props. Circles include a semi-transparent fill for the size legend and stroke outlines for both legends.

AI-generated description
MIT Licensed

Similar vizzes