xxxxxxxxxx
<meta charset="utf-8">
<title>legend</title>
<style>
body {
font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;
}
</style>
<body>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/d3-scale-chromatic.v1.min.js"></script>
<script src="d3.legend.js"></script>
<script>
var margin = {top: 50, right: 50, bottom: 50, left: 50},
width = 960 - margin.left - margin.right,
height = 500 - margin.bottom - margin.top;
var colors = d3.scaleThreshold()
.domain(['','>6',2,3,4,5,6,7,8,9])
.range(d3.schemePuOr[10]);
var legend = d3.legend()
.translate([ width / 4 , height / 4 ])
.colors(colors)
.cb(function() { console.log("Done!"); });
d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
.call(legend);
</script>
https://d3js.org/d3.v4.min.js
https://d3js.org/d3-scale-chromatic.v1.min.js