Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - how to create circle pie canvas like this?

Tags:

html

css

canvas

I really like this element,

this element

but how to create it? I am not sure what's the correct designation of the element...

Thank you very much.

like image 436
user984621 Avatar asked Oct 26 '13 12:10

user984621


1 Answers

This effect can be achieved by layering a couple arc()s:

// bright blue full circle
d.beginPath();
d.arc(50, 50, 50, 0, 2 * Math.PI, false);
d.fillStyle = "#aaeeff";
d.fill();

// dark blue percentage circle
d.beginPath();
d.moveTo(50, 50);
d.arc(50, 50, 50, -0.5 * Math.PI, 0.78 * 2 * Math.PI - 0.5 * Math.PI, false);
d.fillStyle = "#00aaff";
d.fill();

// white inner filler
d.beginPath();
d.moveTo(50, 50);
d.arc(50, 50, 25, 0, 2 * Math.PI, false);
d.fillStyle = "#ffffff";
d.fill();

and finally rendering the text:

d.moveTo(50, 50);
d.fillStyle = "#606060";
d.font = "12pt sans-serif";
d.fillText("78%", 36, 56);

Fiddle: http://jsfiddle.net/j6NVg/

like image 81
Cobra_Fast Avatar answered Sep 24 '22 02:09

Cobra_Fast