Skip to main content
100%

Color and Size Legends

✓ Published0🌍 Public
Ddaigokawabe
Last edited Aug 11, 2020
Created on Aug 10, 2020

This example demonstrates how D3 legends can encode data through color and size. Two separate legends are rendered with SVG: a color legend uses an ordinal scale to map fruit categories to distinct hues, while a size legend uses a square-root scale to represent numeric values with scaled circle radii. The code builds reusable legend components using D3’s data join pattern, applying scales like `scaleOrdinal` and `scaleSqrt`, with manual spacing and text offsets for tick labels.

AI-generated description
MIT Licensed

Similar vizzes