Color and Size Legends
✓ Published2🌍 Public
Ssteveaigbe
Last edited Nov 21, 2020
Created on Nov 21, 2020
This example demonstrates two types of legends for mapping data to visual properties. The color legend uses a `scaleOrdinal` to map categorical names to colors, while the size legend uses a `scaleSqrt` to map numeric values to circle radii with tick marks. Both legends are implemented as reusable functions that append SVG `<g>` elements containing circles and text labels. The code uses D3 v5's selection and merge pattern to efficiently update the legend elements.
AI-generated descriptionMIT Licensed