needed a simple circle legend for a bubble chart that I could pass in values and a domain
to initiate pass in a d3 selection to the circleLegend
function and your dataset domain
and values
:
var l = circleLegend(d3.select('svg g#legend'))
.domain([0, 100])) // the dataset min and max
.range( [0, 80]) // the circle area/size mapping
.values( [8, 34, 89]) // pass in values (e.g. min,mean/median & max)
// optional
.width(500) // it centers to this
.height( 500) // it centers to this
.suffix('') // ability to pass in a suffix e.g. '%'
.circleColor( '#888') // stroke of the circles
.textPadding(40) // left padding on text
.textColor( '#454545') // the fill for text
// and render it
l.render()
note: the number of values
you pass in will correlate to the number of circles
forked from eesur's block: d3 | reusable circle legend
xxxxxxxxxx
<html lang="en">
<head>
<meta charset="utf-8">
<style>
body { font-family: Consolas, monaco, monospace; background: #f43530;}
circle {
stroke-width: 3px;
}
</style>
</head>
<body>
<svg width="960" height="500">
<g id="vis" transform="translate(10, 10)"></g>
</svg>
<script src="https://d3js.org/d3.v4.min.js"></script>
<!-- d3 code -->
<script src=".script-compiled.js" charset="utf-8"></script>
<!-- render code -->
<script>
circleLegend(d3.select('svg g#vis'))
.width(960)
.height(500)
.circleColor('#46454b')
.textColor('#e0e5da')
.suffix('%')
.textPadding(45)
.render()
</script>
</body>
</html>
https://d3js.org/d3.v4.min.js