D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
Servuc
Full window
Github gist
level
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 myColor = "#FFA500"; var myBackgroundColor = "#FFF"; var mySize = 500; var myBorderSize = 0.05; var myStrokeSize = myBorderSize * mySize / 2; var myPercent = 50; var myY = mySize * (myBorderSize + (1 - myBorderSize * 2) * (100 - myPercent) / 100); var myFont = "Verdana"; var myFontSize = mySize / 4; // Feel free to change or delete any of the code you see in this editor! var svg = d3.select("body").append("svg") .attr("width", mySize) .attr("height", mySize) svg.append("path") .attr("d", "M 0 " + myY + " H " + mySize + " V " + mySize + " H 0") .attr("fill", myColor); svg.append("circle") .attr("cy", mySize / 2) .attr("cx", mySize / 2) .attr("r", mySize) .attr("stroke", myBackgroundColor) .attr("stroke-width", mySize) .attr("fill", "transparent"); svg.append("circle") .attr("cy", mySize / 2) .attr("cx", mySize / 2) .attr("r", (mySize / 2) - myStrokeSize / 2) .attr("stroke", myColor) .attr("stroke-width", myStrokeSize) .attr("fill", "transparent"); svg.append("circle") .attr("cy", mySize / 2) .attr("cx", mySize / 2) .attr("r", (mySize / 2) - myStrokeSize * 1.5) .attr("stroke", myBackgroundColor) .attr("stroke-width", myStrokeSize) .attr("fill", "transparent"); svg.append("text") .attr("x", mySize / 2) .attr("y", mySize / 2 + myFontSize / 4) .attr("font-size", myFontSize) .attr("font-family", myFont) .attr("stroke", myBackgroundColor) .attr("stroke-width", myStrokeSize / 5) .attr("text-anchor", "middle") .attr("fill", myColor) .text(myPercent + "%"); </script> </body>
https://d3js.org/d3.v4.min.js