Skip to main content
100%

Color and Size Legends

✓ Published0🌍 Public
Ppanmenghan
Last edited Mar 5, 2020
Created on Mar 5, 2020

This example demonstrates two distinct types of chart legends created with D3.js v5: a color legend using an ordinal scale mapping fruit names to specific colors, and a size legend using a square-root scale to map numeric tick values to circle radii. Both legends are rendered as SVG groups, with circles and text labels positioned programmatically via `attr('transform')` calls. The color legend uses `scaleOrdinal` for categorical colors, while the size legend uses `scaleSqrt` and `ticks()` to generate evenly spaced, non-zero values, with circles filled using a semi-transparent black.

AI-generated description
MIT Licensed

Similar vizzes