Animated Percentage Circles with JavaScript

This tutorial shows you that percentage circles or progress circles can be created without the aid of jQuery. With the use of JavaScript on HTML5 canvas, the same effect can be produced easily, as shown below in the animation.




The Code for the above percentage circle is as follows; you can modify and use it without worrying about JQuery.

var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
//Declare variables for the angle, increment and percentage
var a = 0, b=5,d;
function draw() {
a = a + b;
c = Math.PI * a / 180;
d = Math.round(100 * a / 360);
context.clearRect(0, 0, 500, 500);
context.lineWidth = 25;
//Draw a dark static circle
//Display the percentage
context.font = 'bold 30pt Calibri';
context.fillText(d + '%', 180, 210);
context.fillStyle = "blue";
//Draw the dynamic circle
//Gradient for the dynamic circle
var grd = context.createRadialGradient(200, 200, 102, 200, 200, 104);
grd.addColorStop(0, 'lightblue');
grd.addColorStop(1, 'blue');
context.strokeStyle = grd;
//Call the function every in 150 milliseconds
window.setInterval(draw, 150);


Of course, the code can be easily amended to control the animation: for instance, this animation runs for ever; with setTimeout() function, however, the number of times that the animation runs can be easily controlled.






Resources at Fingertips

There is a significant selection of tutorials here, covering ASP.Net, HTML5, CSS3 and JavaScript. They are categorized clearly for you to access them easily on any device - desktops/laptops, smartphones and laptops.
There are quite a few of them on HTML5 Canvas and CSS3. In addition, there are tutorials on JavaScript and ASP.Net too.


Stand Out - from the crowd


"There's no such thing as a free lunch."

The best things in nature are free with no strings attached - fresh air, breathtakingly warm sunshine, scene of meadow on the horizon...

Vivax Solutions, while mimicking nature, offers a huge set of tutorials along with interactive tools for free.

Please use them and excel in the sphere of science education.

Everything is free; not even registration is required.



Recommended Reading


The best book to master HTML5 canvas animations. The author tells you how to manipulate the canvas element with JavaScript in a progressive way - starting from the easier to harder worked examples. It is ideal for anyone who wants to be a game developer in HTML5.