Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Color and Size Legends

Public visualization

Color and Size Legends

1 star1🌍 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

Comments

Sign in to join the discussion.

MIT Licensed