🌍 Public
Color and size legends
This example demonstrates how to construct reusable legends for categorical color scales in D3 v5. A color legend maps fruit names to distinct colors using `scaleOrdinal`, rendering circles with corresponding fills and text labels. The legend is implemented as a custom function that leverages D3’s data-join pattern with `selection.merge` to handle updates efficiently. The SVG output positions each legend item vertically with configurable spacing, circle radius, and text offset.
AI-generated descriptionAn example including some commonly used features of SVG.
MIT Licensed








Comments
Sign in to join the discussion.