\n";
/*
The piechart function
Arguments are an aray of values, the centre coordinates x and y, and
the radius of the piechart.
*/
function piechart($data, $cx, $cy, $radius) {
$chartelem = "";
$max = count($data);
// $colours = array('#4e9a06','#a40000','#204a87','#5c3566','#ce5c00');
$colours = array('#73d216','#cc0000','#3465a4','#75507b','#f57900');
// $colours = array('#8ae234','#ef2929','#729fcf','#ad7fa8','#fcaf3e');
$sum = 0;
foreach ($data as $key=>$val) {
$sum += $val;
}
$deg = $sum/360; // one degree
$jung = $sum/2; // necessary to test for arc type
/* Data for grid, circle, and slices */
$dx = $radius; // Starting point:
$dy = 0; // first slice starts in the East
$oldangle = 0;
/* Loop through the slices */
for ($i = 0; $i<$max; $i++) {
$angle = $oldangle + $data[$i]/$deg; // cumulative angle
$x = cos(deg2rad($angle)) * $radius; // x of arc's end point
$y = sin(deg2rad($angle)) * $radius; // y of arc's end point
$colour = $colours[$i];
if ($data[$i] > $jung) {
// arc spans more than 180 degrees
$laf = 1;
}
else {
$laf = 0;
}
$ax = $cx + $x; // absolute $x
$ay = $cy + $y; // absolute $y
$adx = $cx + $dx; // absolute $dx
$ady = $cy + $dy; // absolute $dy
$chartelem .= "\n";
$chartelem .= "";
$dx = $x; // old end points become new starting point
$dy = $y; // id.
$oldangle = $angle;
}
return $chartelem;
}
?>