Skip to main content
100%

Color and Size Legends

✓ Published1🌍 Public
CCassie
Last edited Oct 23, 2021
Created on Oct 16, 2021

This example demonstrates two distinct legend types for different data encodings: a color legend with categorical swatches for fruits and a size legend with scaled circles for numeric values. Built with D3 v5, it renders SVG elements using reusable functions `colorLegend` and `sizeLegend`. The color legend uses `scaleOrdinal` with discrete colors, while the size legend employs `scaleSqrt` and generates ticks via `sizeScale.ticks()`. Both legends position circles and text labels with explicit spacing and offset values.

AI-generated description
MIT Licensed

Similar vizzes