Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Color and size legends

Public visualization

Viewing a saved revision (read-only)

45a6a2bf02194105bf1217d5fdc316cb

Color and size legends

0 stars0🌍 Public
JJason-Manbodh
Last edited Jun 4, 2020
Created on Jun 4, 2020

This example demonstrates two custom legend components for mapping data values to visual encodings: a color legend for ordinal categories and a size legend for quantitative values. The color legend displays colored circles for fruits, while the size legend uses scaled circle radii to represent numeric values. Built with D3 v5, the code defines reusable functions `colorLegend` and `sizeLegend` that use `scaleOrdinal`, `scaleSqrt`, and selection joins to render SVG elements dynamically.

AI-generated description