Skip to main content
100%

Color and Size Legends

✓ Published1🌍 Public
AApoorv Agnihotri
Last edited Jan 28, 2020
Created on Jan 28, 2020

This example demonstrates a reusable legend component for mapping ordinal color scales to categorical data. The visualization renders four fruit categories—apple, lemon, lime, and orange—as colored circles, with each circle’s fill derived from a `scaleOrdinal` and its position spaced vertically via a custom `colorLegend` function. The code uses D3 v5’s `select`, `scaleOrdinal`, and data join pattern to create SVG `<g>` groups containing circles and text labels. The legend is styled with CSS classes for tick elements, and the SVG container includes a border for visual framing.

AI-generated description
MIT Licensed

Similar vizzes