Colour and Size Legends
✓ Published0🌍 Public
This example demonstrates two types of legend components rendered as SVG in D3 v5: a colour legend using `scaleOrdinal` with discrete fruit categories, and a size legend built on `scaleSqrt` for continuous numeric values. The colour legend maps domain values to colored circles with labels, while the size legend displays tick marks with circle radii proportional to data values. Both legends reuse enter/merge/exit selections for dynamic updates, with tick text and circles styled via CSS. The code defines reusable `colourLegend` and `sizeLegend` functions, called with custom spacing, offsets, and tick counts.
AI-generated descriptionMIT Licensed