Adding a chart legend in D3
You need to bind data to the nodes (rectangles and text elements) that make up the legend. Currently you get an error when trying to style rectangles: Uncaught TypeError: Cannot read property ‘1’ of undefined The reason: there’s no bound data legend.append(“rect”) /*…*/ .style(“fill”, function(d) { // d <—- is undefined return color_hash[dataset.indexOf(d)][1] }); Notice … Read more