JSFiddle - React, Tailwind, and code Playground
HTML
<div id="canvas" style="width:100%; text-align:center;">
<div class="circle" id="circles-1">
</div>
</div>
CSS
body {
margin: 2em auto;
max-width: 30em;
font-size: 1.5em;
line-height: 2;
}
h1 {
line-height: 1.1;
}
#canvas .circle {
display: inline-block;
margin: 1em;
}
.circles-decimals {
font-size: .4em;
}
JavaScript
// circles
// copyright Artan Sinani
// https://github.com/lugolabs/circles
/*
Lightwheight JavaScript library that generates circular graphs in SVG.
Call Circles.create(options) with the following options:
id - the DOM element that will hold the graph
radius - the radius of the circles
width - the width of the ring (optional, has value 10, if not specified)
value - init value of the circle (optional, defaults to 0)
maxValue - maximum value of the circle (optional, defaults to 100)
text - the text to display at the centre of the graph (optional, the current "htmlified" value will be shown if not specified)
if `null` or an empty string, no text will be displayed
can also be a function: the returned value will be the displayed text
ex1. function(currentValue) {
return '$'+currentValue;
}
ex2. function() {
return this.getPercent() + '%';
}
colors - an array of colors, with the first item coloring the full circle
(optional, it will be `['#EEE', '#F00']` if not specified)
duration - value in ms of animation duration; (optional, defaults to 500);
if 0 or `null` is passed, the animation will not run
wrpClass - class name to apply on the generated element wrapping the whole circle.
textClass: - class name to apply on the generated element wrapping the text content.
API:
updateRadius(radius) - regenerates the circle with the given radius (see spec/responsive.html for an example hot to create a responsive circle)
updateWidth(width) - regenerates the circle with the given stroke width
updateColors(colors) - change colors used to draw the circle
update(value, duration) - update value of circle. If value is set to true, force the update of...