Skip to main content
100%

Colour and Size Legends

✓ Published0🌍 Public
Ccornshoots
Last edited Mar 17, 2021
Created on Mar 16, 2021
Forked from Singular elements

This example demonstrates two distinct legend types for mapping data to visual encodings. A color legend displays ordinal categories—apple, lemon, lime, and orange—paired with distinct hues using `d3.scaleOrdinal`. Adjacent to it, a size legend uses `d3.scaleSqrt` to map a continuous numeric domain from 0 to 10 to circle radii, filtering out zero and reversing tick order for display. Both legends are built with reusable D3 functions that append SVG groups, circles, and text elements, with tick styling applied via CSS classes.

AI-generated description
MIT Licensed

Similar vizzes