Usage

Client-side

Version

This is the version compatible with d3v4, please go here for the version compatible with d3v3

Changes when moving to d3v4 of this component

Flattened naming for accessing functions

d3.legend.color => d3.legendColor



d3.legend.size => d3.legendSize



d3.legend.symbol => d3.legendSymbol

NPM package no longer binds to global d3, is now just an object with the three legend functions

CDN

You can add the latest version of d3-legend hosted on cdnjs.

https://cdnjs.com/libraries/d3-legend

Include the file directly

You must include the d3 library before including the legend file. Then you can simply add the compiled js file to your website:

npm

Already using d3? Great! You can add the d3 legend as a node module by running:

npm i d3-svg-legend -S

Github + feedback

The full source code is available on github. I would love to hear from you about any additional features that would be useful, please say hi on twitter @DataToViz.