Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Colour and Size Legends

Public visualization

Viewing a saved revision (read-only)

d76e2015470c4596bf124bcb52241640

Colour and Size Legends

0 stars0🌍 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