Skip to content

Instantly share code, notes, and snippets.

@lisawilliams
Created March 20, 2017 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lisawilliams/d228616978c1198a8ca3eb554dfd31e6 to your computer and use it in GitHub Desktop.
Save lisawilliams/d228616978c1198a8ca3eb554dfd31e6 to your computer and use it in GitHub Desktop.
Scatterplot example 7
// draw legend
var legend = svg.selectAll(".legend")
.data(color.domain())
.enter().append("g")
.attr("class", "legend")
.attr("transform", function(d, i) { return "translate(0," + i * 20 + ")"; });
// draw legend colored rectangles
legend.append("rect")
.attr("x", width - 18)
.attr("width", 18)
.attr("height", 18)
.style("fill", color);
// draw legend text
legend.append("text")
.attr("x", width - 24)
.attr("y", 9)
.attr("dy", ".35em")
.style("text-anchor", "end")
.text(function(d) { return d;})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment