Circles
The circular graphs with the numerical value in the center have been a great way of visualizing data lately. For example, they are used to great effect by awwwards.
Circles makes creating the charts very easy. Circles is a lightweight JavaScript library without dependencies, that generates the SVG chart on the fly.
Create a graph by calling:
Circles.create({
id: 'circles-1',
radius: 60,
value: 43,
maxValue: 100,
width: 10,
text: function(value){return value + '%';},
colors: ['#D3B6C6', '#4B253A'],
duration: 400,
wrpClass: 'circles-wrp',
textClass: 'circles-text',
styleWrapper: true,
styleText: true
})
where
id- the DOM element that will hold the graphradius- the radius of the circlesvalue- init value of the circle (optional, defaults to 0)maxValue- maximum value of the circle (optional, defaults to 100)width- the width of the ring (optional, has value 10, if not specified)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's duration; defaults to 500; if 0 ornullis passed, the animation will not runwrpClass- class name to apply on the generated element wrapping the whole circletextClass- class name to apply on the generated element wrapping the text contentstyleWrapper- whether or not to add inline styles to the wrapper element (defaults to true)styleText- whether or not to add inline styles to the text (defaults to true)text- the text to display at the center of the graph (optional, the current "htmlified" value will be shown); ifnullor an empty string, no text will be displayed; it can also be a function: the returned value will be the displayed text
API
myCircle.updateRadius(Number radius)
Regenerates the circle with the given radius.
myCircle.updateWidth(Number width)
Regenerates the circle with the given width.
myCircle.updateColors(Array colors)
Change colors used to draw the circle.
myCircle.update(Number value [, Number duration])
Set the value of the circle to value. Animation will take duration ms to execute. If no duration is given, the default duration set in the constructor will be used. If you don't want animation, set duration to 0.
myCircle.getPercent()
Returns the percentage value of the circle, based on its current value and its max value.
Styles
The styles have been specified inline to avoid external dependencies, but they can be overridden via CSS easily, being simply HTML elements. Two classes are exposed for this: circles-wrp (the element wrapping the whole circle) and circles-text (the element wrapping the text content). You can overwrite these classes by sending properties wrpClass and/or textClass to the constructor.
Compatibility
Browsers that support SVG.
Inspirations
Code and ideas have been borrowed from Highcharts and Wout Fierens's svg.js.