Colour and size legends
✓ Published0🌍 Public
This example demonstrates how to build custom colour and size legends for a scatterplot using D3.js version 5. It uses `d3.scaleOrdinal` and `d3.scaleSqrt` to map categorical and numerical data, respectively, with the legends rendered as SVG groups of circles and text labels. The colour legend shows apples and lemons with distinct red and yellow fills, while the size legend displays five tick values from 0 to 10 with increasing circle radii. The code imports modular functions `colourLegend` and `sizeLegend` and updates DOM elements via D3’s selection join pattern.
AI-generated descriptionDemonstrates fundamental DOM manipulation using D3.js by making a smiley face whose eyebrows move.
MIT Licensed