🌍 Public
Viewing a saved revision (read-only)
baaae9f68d3d4531ad2e89027e8c6ebb
Colour and Size Legends
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 description