Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Color legend

Public visualization

Viewing a saved revision (read-only)

4f60064be9d84c21a41bf8e27d00c865

Color legend

0 stars0🌍 Public
AAnShed
Last edited Jun 29, 2020
Created on Jun 29, 2020
Forked from Cars Scatter Plot

This example demonstrates two reusable legend components for D3 visualizations: an ordinal color legend for categorical data and a quantitative size legend for numeric scales. The color legend maps fruit names to distinct colors, while the size legend uses a square-root scale to map values from 0 to 10 to circle radii. Both legends are rendered as SVG using d3.select, append, and merge operations, with the color legend applying a scaleOrdinal and the size legend using scaleSqrt. The code uses D3 v5 APIs including selection.call, data, and attr to construct the tick groups dynamically.

AI-generated description