Legend

This shows how to use the legend module.

Code

// setup legend
var legend = legendBox()
  .duration(1000)
  .width(600)
  .height(100)
  .colors(d3.scale.category20());

// draw legend
d3.select('#legend-box')
  .datum(data)
  .call(legend);

Data

var data = [
    {  
      "name": "bananas"
    },
    {
      "name": "kiwis"
    },
    {  
      "name": "guavas"
    },
    {
      "name": "mangos"
    },
    {  
      "name": "grapefruit"
    },
    {
      "name": "pears"
    },
    {  
      "name": "bananas"
    },
    {
      "name": "kiwis"
    },
    {  
      "name": "guavas"
    }
  ];