Skip to main content
100%

Colour and size legends

✓ Published0🌍 Public
MMatan
Last edited Nov 14, 2020
Created on Nov 14, 2020

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 description

Demonstrates fundamental DOM manipulation using D3.js by making a smiley face whose eyebrows move.

MIT Licensed

Similar vizzes