Circles (Pie chart)
A lightweight JavaScript library that generates circular graphs in SVG.
Circles documentationHow to use
Copy-paste the following <script>
near the end of your pages under JS Implementing Plugins to enable it.
<script src="./node_modules/appear/dist/appear.min.js"></script>
<script src="./node_modules/circles.js/circles.js"></script>
Copy-paste the following <script>
near the end of your pages under JS Implementing Plugins to enable it.
<script src="./assets/js/hs.circles.js"></script>
Copy-paste the init function under JS Plugins Init., before the closing </body>
tag, to enable it.
<script>
(function() {
// INITIALIZATION OF CIRCLES
// =======================================================
setTimeout(() => {
HSCore.components.HSCircles.init('.js-circle')
})
});
</script>
Basic example
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(30, 32, 34, 0.1)", "#1e2022"],
"radius": 50,
"width": 4,
"additionalText": "",
"textFontSize": 26,
"textClass": "circles-chart-content",
"textColor": "#1e2022"
}'></div>
<!-- End Circle -->
Text class
Use "secondaryText": ""
to add a secondary text.
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 10,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"fgStrokeLinecap": "round",
"fgStrokeMiterlimit": "10",
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 50,
"width": 6,
"additionalText": "",
"textClass": "circles-chart-content",
"textColor": "#377dff",
"textFontSize": 32,
"secondaryText": "some text",
"secondaryTextColor": "#77838f",
"secondaryTextFontSize": "13",
"secondaryTextFontWeight": "400",
"dividerSpace": "10"
}'></div>
<!-- End Circle -->
Colors
An array of colors. Add any color code "colors": ["rgba(55, 125, 255, 0.1)", "#377dff"]
to change the appearance of a circle.
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 50,
"width": 4,
"additionalText": "",
"textFontSize": 26,
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(0, 201, 167, 0.1)", "#00c9a7"],
"radius": 50,
"width": 4,
"additionalText": "",
"textFontSize": 26,
"textClass": "circles-chart-content",
"textColor": "#00c9a7"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(0, 223, 252, 0.1)", "#00dffc"],
"radius": 50,
"width": 4,
"additionalText": "",
"textFontSize": 26,
"textClass": "circles-chart-content",
"textColor": "#00dffc"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(255, 193, 7, 0.1)", "#ffc107"],
"radius": 50,
"width": 4,
"additionalText": "",
"textFontSize": 26,
"textClass": "circles-chart-content",
"textColor": "#ffc107"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(222, 68, 55, 0.1)", "#de4437"],
"radius": 50,
"width": 4,
"additionalText": "",
"textFontSize": 26,
"textClass": "circles-chart-content",
"textColor": "#de4437"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(30, 32, 34, 0.1)", "#1e2022"],
"radius": 50,
"width": 4,
"additionalText": "",
"textFontSize": 26,
"textClass": "circles-chart-content",
"textColor": "#1e2022"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(119, 131, 143, 0.1)", "#77838f"],
"radius": 50,
"width": 4,
"additionalText": "",
"textFontSize": 26,
"textClass": "circles-chart-content",
"textColor": "#77838f"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(255, 255, 255, 0.1)", "#ffffff"],
"radius": 50,
"width": 4,
"additionalText": "",
"textFontSize": 26,
"textClass": "circles-chart-content",
"textColor": "#ffffff"
}'></div>
<!-- End Circle -->
Size
Fancy larger or smaller circles? Control them with "radius":
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 80,
"width": 4,
"textFontSize": 40,
"textFontWeight": 700,
"additionalText": "",
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 60,
"width": 4,
"textFontSize": 28,
"additionalText": "",
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 40,
"width": 4,
"textFontSize": 22,
"additionalText": "",
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 30,
"width": 4,
"textFontSize": 16,
"additionalText": "",
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
Stroke width
Adjusted with of a ring with "width":
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 50,
"width": 1,
"textFontSize": 22,
"additionalText": "",
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 50,
"width": 3,
"textFontSize": 22,
"additionalText": "",
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 50,
"width": 6,
"textFontSize": 22,
"additionalText": "",
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 50,
"width": 10,
"textFontSize": 22,
"additionalText": "",
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 50,
"width": 16,
"textFontSize": 22,
"additionalText": "",
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
Stroke linecap
The stroke-linecap
attribute is a presentation attribute defining the shape to be used at the end of open subpaths when they are stroked.
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 60,
"width": 6,
"textFontSize": 22,
"fgStrokeLinecap": "square",
"additionalText": "",
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 60,
"width": 6,
"textFontSize": 22,
"fgStrokeLinecap": "round",
"additionalText": "",
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
Max value
Returns the max value of a circle.
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 17,
"maxValue": 25,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 60,
"width": 6,
"textFontSize": 22,
"additionalText": "",
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 29,
"maxValue": 50,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 60,
"width": 6,
"textFontSize": 22,
"additionalText": "",
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
Type
Any unit measurements or icons can be used to demonstrate the stats. Use "type": ""
to show texts or numbers, or use "type": "iconic", "icon": "<i class=\"far fa-bell\"></i>",
for icons.
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 60,
"width": 6,
"textFontSize": 22,
"type": "iconic",
"icon": "<i class=\"tio-notifications-on-outlined\"></i>",
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 60,
"width": 6,
"textFontSize": 22,
"additionalText": "%",
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 60,
"width": 6,
"textFontSize": 22,
"additionalText": "k",
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
Animation speed
Value in ms
of animation's duration. For example, "duration": 500
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 500,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 60,
"width": 6,
"textFontSize": 22,
"additionalText": "",
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 60,
"width": 6,
"textFontSize": 22,
"additionalText": "",
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 54,
"maxValue": 100,
"duration": 5000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 60,
"width": 6,
"textFontSize": 22,
"additionalText": "",
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
Additional text
Additional texts are useful to describe/highlight the main values and they can be added to the value either after, like this:
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 25,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 80,
"width": 6,
"fgStrokeLinecap": "round",
"additionalText": " Top",
"textFontSize": 24,
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
Or before the value, like this: "additionalTextType": "prefix"
should be added to put the additional text before the value.
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 70,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 80,
"width": 6,
"fgStrokeLinecap": "round",
"additionalText": " Top ",
"additionalTextType": "prefix",
"textFontSize": 24,
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
Control additional text size with "textFontSize":
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 10,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 80,
"width": 6,
"fgStrokeLinecap": "round",
"additionalText": " Top ",
"additionalTextType": "prefix",
"textFontSize": 10,
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 10,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 80,
"width": 6,
"fgStrokeLinecap": "round",
"additionalText": " Top ",
"additionalTextType": "prefix",
"textFontSize": 16,
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 10,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 80,
"width": 6,
"fgStrokeLinecap": "round",
"additionalText": " Top ",
"additionalTextType": "prefix",
"textFontSize": 22,
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 10,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 80,
"width": 6,
"fgStrokeLinecap": "round",
"additionalText": " Top ",
"additionalTextType": "prefix",
"textFontSize": 32,
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
Control text font weight with "textFontWeight":
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 10,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 80,
"width": 6,
"fgStrokeLinecap": "round",
"additionalText": " Top ",
"additionalTextType": "prefix",
"textFontSize": 32,
"textFontWeight": 400,
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 10,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 80,
"width": 6,
"fgStrokeLinecap": "round",
"additionalText": " Top ",
"additionalTextType": "prefix",
"textFontSize": 32,
"textFontWeight": 600,
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
Hide value
Hide the value of a circle to make the additional text main value via "isHideValue": true
<!-- Circle -->
<div class="js-circle"
data-hs-circles-options='{
"value": 10,
"maxValue": 100,
"duration": 2000,
"isViewportInit": true,
"colors": ["rgba(55, 125, 255, 0.1)", "#377dff"],
"radius": 80,
"width": 6,
"fgStrokeLinecap": "round",
"isHideValue": true,
"additionalText": "Tripling",
"additionalTextType": "prefix",
"textFontSize": 22,
"textFontWeight": 300,
"textClass": "circles-chart-content",
"textColor": "#377dff"
}'></div>
<!-- End Circle -->
Methods
Parameters | Description | Default value |
---|---|---|
|
The radius of the circles. | 80 |
|
Value in ms of animation's duration; defaults to 500; if 0 or null is passed, the animation will not run. |
1000 |
|
Class name to apply on the generated element wrapping the whole circle. | 'circles-wrap' |
|
An array of colors, with the first item coloring the full circle (optional, it will be ['#EEE', '#F00'] if not specified). | ["#377dff", "#e7eaf3"] |
|
Hides the animated value of the graph. | false |
|
Distance between main and secondary texts. | null |
|
The stroke-linecap attribute is a presentation attribute defining the shape to be used at the end of open subpaths when they are stroked. Available values:
|
null |
|
The stroke-miterlimit attribute is a presentation attribute defining a limit on the ratio of the miter length to the stroke-width used to draw a miter join. When the limit is exceeded, the join is converted from a miter to a bevel. |
null |
|
additionalTextType - if the value is "prefix", then the value of the additionalText parameter will be displayed before the numerical value of the chart, otherwise after that. |
null |
|
Postfix/prefix that is added to the numeric value of the graph. | null |
|
Font size of the numerical value of the graph. | null |
|
Font weight of the numerical value of the graph. | null |
|
Graph numerical color. | null |
|
Text helper displayed below the numerical value of the graph. | null |
|
Font weight of the text helper. | null |
|
Font size of the text helper. | null |
|
Color of the text helper. | null |