Skip to main content
100%

Color and Size Legends

✓ Published0🌍 Public
MMihir Sawant
Last edited Nov 7, 2018
Created on Oct 1, 2018

This example demonstrates two distinct types of legends for data visualization: a color legend and a size legend. The color legend maps categorical fruit names to distinct colors using `scaleOrdinal`, while the size legend uses `scaleSqrt` to represent numeric values with proportional circle radii. Both legends are rendered as SVG groups, with circles and text labels positioned using `attr('transform', ...)`. The code employs D3 v5's selection and merge methods to efficiently update the legends, and the circles are styled with a black stroke for visual clarity.

AI-generated description
MIT Licensed

Similar vizzes