Pie Chart

JavaScript Kullanımı

46%   Memnun
25%   Notr
22%   Memnuniyetsiz
8%   Yorumsuz



Ornek Kod
function pieChart(data, R = 110, C = 20) {
canvas.width = 2*(R+C); canvas.height = 2*(R+C);
const cx = canvas.getContext("2d");
const k = 2 * Math.PI / 100;
let a = -0.5 * Math.PI; // start at -pi/2
for (let x of data) {
const delta = x.percent * k;
cx.beginPath();
// center=(R+C, R+C) radius=R
// clockwise by delta
cx.arc(R+C, R+C, R, a, a + delta);
a += delta;
cx.lineTo(R+C, R+C);
cx.fillStyle = x.color;
cx.fill();
}
}

Ref: Eloquent JavaScript, Chap 17