Fork of D3 D3 Color and Size Legends
✓ Published0🌍 Public
This example demonstrates how to build color and size legends for D3 visualizations using modular JavaScript functions. It shows a color legend with circles representing different fruit types, encoded through an ordinal color scale. The code defines a reusable `colorLegend` component that binds data to SVG groups, appending circles and text labels. Using D3 v7’s `scaleOrdinal`, the example maps categorical domains to specific colors, while SVG rendering handles the visual output. The implementation highlights a clean separation between the legend component and the main script’s render logic.
AI-generated descriptionColor and Size Legends
Topics covered:
- Creating a color legend component
- Encoding area using a square root scale
- Computing ticks from size scale
- Creating a size legend component
- Tweaking the styles
MIT Licensed