Skip to main content
100%

D3.js Step by Step: Step 3 - Adding a Legend

✓ Published0🌍 Public
SSkyBTW
Last edited Feb 22, 2018
Created on Feb 22, 2018

This example demonstrates a donut chart with a legend, showing seven categorical labels with zero counts. The visualization uses D3 v4 to generate SVG paths via `d3.arc` and `d3.pie`, with a categorical color scale from `d3.scaleOrdinal(d3.schemeCategory20)`. A legend is added on the left side, positioning colored rectangles and text labels using the same color scale’s domain. The code manually calculates legend offsets based on fixed rectangle sizes and spacing, rendering the static dataset without interaction.

AI-generated description

Built with blockbuilder.org

mit Licensed

Similar vizzes