D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
mforando
Full window
Github gist
Legend Component Mock Up
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } </style> </head> <body> <script> var randvals = [10,20,50]; var width = 200; var pad = 40; var radiusScale = d3.scaleLinear() .domain([Math.sqrt(5),Math.sqrt(50)]) .range([2,width/2 - pad]); // Feel free to change or delete any of the code you see in this editor! var svg = d3.select("body").append("svg") .attr("width", width) .attr("height", width) svg.append("text") .attr("dx",width/2) .attr("dy",pad/2) .style("font-family","Franklin Gothic Medium") .style("text-anchor","middle") .text('Legend') svg.selectAll("circle") .data(randvals) .enter() .append("circle") .attr("r",(d)=>{return radiusScale(Math.sqrt(d))}) .attr("fill","none") .attr("stroke","rgba(0,0,0,.5)") .attr("cy", (d)=>{return width - pad - radiusScale(Math.sqrt(d))}) .attr("cx", width/2) svg.selectAll(".labels") .data(randvals) .enter() .append("text") .attr("class","labels") .text((d)=>{return d}) .attr("fill","black") .style("text-anchor","middle") .style("dominant-baseline","text-before-edge") .style("font-size","11px") .attr("y", (d)=>{return width - pad - radiusScale(Math.sqrt(d))*2}) .attr("x", width/2) </script> </body>
https://d3js.org/d3.v4.min.js