I had a look around today for a handy pie chart that I could quickly drop into a new web app I'm working on and it seems there's a lot of bloated solutions out there. I like to keep things short and sweet so I found this one online and edited it to make it a bit more user friendly. Enjoy!
Please see right hand pane before copying my code >>
//ADD THIS BETWEEN YOUR HEAD TAGS OR TO AN EXTERNAL JS FILE:
var pieProps = new Object()
function pieChart(canvas, radius, percentages, n, colors) {
var canvas = document.getElementById(canvas)
var a = pieProps.a = canvas.getContext("2d");
pieProps.colors = colors
pieProps.i = 0
canvas.width = 3.5*radius;
canvas.height = 2.5*radius;
x = y = canvas.height/2;
a.font = "bold 12px Arial";
var u = 0;
var v = 0;
for (i=0;i < percentages.length;i++) {
v += percentages[i];
W(i)(x,y,radius,u,v);
u = v;
a.fillText(n[i], x+radius+10, y-radius/2+i*18);
}
}
function W(x,y,r,u,v) {
var a = pieProps.a
if(r) {
a.beginPath();
a.moveTo(x,y);
a.arc(x, y , r, (u||0)/50*Math.PI, (v||7)/50*Math.PI, 0);
a.lineTo(x,y);
a.fill();
} else {
a.fillStyle = '#'+pieProps.colors[pieProps.i++];
}
return W;
}
//ADD THIS TO YOUR PAGE SOMEWHERE:
<canvas id="c"> Your browser does not support the canvas element. </canvas>
//EXAMPLE USAGE:
<body onload="pieChart('c', 100, [70,25,15], ['Carbs','Protein','Fat'], ['CCCCCC','FFBF43','FF850D'])">
This code is adapted from http://reubencrane.com/canvas_pie.html
18 comments:
Nice adaptation, glad I could help!
Great example. useful information. I am learn for Jquery script on
Nice coding. http://www.dreamdestinations.in/
nice things ..a great example
If anyone want learn more about Cakephp image behavior...This is the nice blog to read...
cakephplogics.blogspot.com
nice things ..a great example
If anyone want learn more about Cakephp image behavior...This is the nice blog to read...
http://cakephplogics.blogspot.com
Thank you for sharing. Good code. I have found an interesting chart http://www.pptstar.com/diagrams/pie-charts/, but do not know how I can use them. I want to try to make such chart on your example.
canada goose
coach factory outlet
coach outlet
ray ban sunglasses
fit flops
canada goose jackets
kate spade outlet
cheap oakleys
birkenstock sandals
birkenstocks
20161228caiyan]
\
Excellent and very cool idea and the subject at the top of magnificence and I am happy to this post..Interesting post! Thanks for writing it. What's wrong with this kind of post exactly? It follows your previous guideline for post length as well as clarity..Website for school uk
coach outlet
michael kors outlet
nfl jerseys wholesale
christian louboutin outlet
coach outlet online
canada goose outlet
canada goose outlet store
canada goose outlet
christian louboutin sale
pandora outlet
shenyuhang20180608
شركة تنظيف خزانات بالرياض
شركة تنظيف كنب بالرياض
شركة تنظيف مكيفات بالرياض
شركة تسليك مجارى بالرياض
Buy Mattress naz online on Treasurebox store items which you will be provide easily on a single click.
Due to the level of quality provided by our company Al-Safa Company in Al-Ahsa شركة تنظيف بالاحساء of cleaning and cleaning services of air conditioning and sewage and insect control on all household services that we do,شركة تنظيف مكيفات بالاحساء and taking our prices suitable for all segments of society, has become the best and most important company in the field of cleaning. شركة تنظيف خزانات بالاحساء In order to maintain our success and progress, the company strives to continue along the same lines, through continuous development and the constant pursuit of following all that is best for the masters of customers. شركة مكافحة حشرات بالاحساء So, never hesitate our dear customer to contact us if you want daily, weekly or monthly cleaning for your home, your garden or your company, شركة تسليك مجارى بالاحساء or even want any kind of cleaning services, we will promptly meet your request with perfect quality and low cost .
شركة الصفرات لكشف التسربات بالرياض
شركة الصفرات للتنظيف بالرياض
شركة الصفرات لتنظيف الخزانات بالرياض
https://www.al-safaa.com/
شركة الصفرات للتنظيف بالرياض
شركة الصفرات لتنظيف الخزانات بالرياض
شركة الصفرات لمكافحة الحشرات بالرياض
شركة الصفرات لنقل الاثاث بالرياض
شركة الصفرات لكشف التسربات بالرياض
https://www.beat-elkhibra.com/
شركة تنظيف بالمدينة المنورة
شركة نظافة بالمدينة المنورة
https://www.cleaningcompanyusa.com/
شركة القيصر لخدمات التنظيف المتكاملة تنظيف منازل وفلل ومكافحة حشرات
النخبه الدوليه لخدمات تنظيف المنازل والفلل والقصور
شركة اللؤلؤة الذهبية لمكافحة الحشرات
شركة درع الثقة لخدمات التنظيف والتعقيم
شركة درع الثقة لخدمات التنظيف والتعقيم
شركة الندي لخدمات تنظيف منازل وتنظيف فلل وتنظيف كنب وسجاد وستائر
الصقر الذهبي لتظيف المباني تنظيف فلل-شقق-كنب-سجاد-جلي رخام
شركة الثقة لخدمات التنظيف والتعقيم تنظيف منازل فلل شقق موكيت كنب سجاد
شركه بركه للتنظيف ومكافحه الحشرات
شركة تنظيف في العين
شركة تنظيف شقق بالجبيل
شركة تنظيف فلل بالجبيل
شركة مكافحة حشرات بالجبيل
شركة تنظيف منازل براس تنورة
شركة مكافحة حشرات براس تنورة
شركة تنظيف مكيفات براس تنوره
شركة تنظيف منازل بالنعيريه
شركة مكافحة حشرات بالنعيريه
شركة تنظيف مكيفات بالنعيريه
شركة تنظيف منازل بالخفجى
شركة مكافحة حشرات بالخفجى
شركة تنظيف مكيفات بالخفجى
شركة تنظيف كنب وسجاد بالخرج
شركة تنظيف مجالس بالباحه
شركة تنظيف خزنات بالاحساء
شركة تركيب طارد الحمام بالدمام
شركة تنظيف شقق بجازان
شركة تنظيف خزانات بجازان
شركة تسليك مجاري بالخرج
شركة عزل خزانات بالدمام
شركة تنظيف فلل بالقطيف
شركة مكافحة حشرات بالقطيف
شركة تنظيف منازل بالخبر
شركة تنظيف خزانات بالخبر
شركة تنظيف شقق بالخبر
شركة تنظيف فلل بالخبر
شركة تنظيف كنب بالخبر
شركة مكافحة حشرات بالخبر
شركة تنظيف منازل بالجبيل
شركة تنظيف خزانات بالجبيل
Post a Comment