note 113735 added to function.imagefilledarc
| From: | floripondia dot 88 at hotmail dot com | Date: | Fri, 22 Nov 2013 16:28:31 +0000 |
| Subject: | note 113735 added to function.imagefilledarc | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-197621@lists.php.net to get a copy of this message | ||
If you want to make a pie graph with exploded slices and data shows on each one and data side right
too you can use this snippet.
<?php
$values = array("2010" => 1950, "2011" => 750, "2012" =>
2100, "2013" => 580, "2014" => 5000);
$total = count($values);
$data = ($total == 0) ? array(360) : array_values($values);
$keys = ($total == 0) ? array("") : array_keys($values);
$radius = 30;
$imgx = 1800 + $radius;
$imgy = 600 + $radius;
$cx = 400 + $radius;
$cy = 200 + $radius;
$sx = 800;
$sy = 400;
$sz = 150;
$data_sum = array_sum($data);
$angle_sum = array(-1 => 0, 360);
$typo = "./helvetica.ttf";
$im = imagecreate($imgx, $imgy);
imagecolorallocate($im, 255, 255, 255);
$color = array(
array(220, 20, 60),
array(77, 33, 114),
array(249, 141, 53),
array(158, 37, 59),
array(1, 128, 128),
array(28, 94, 160),
//array(206, 16, 118),
array(43, 67, 86),
//array(155, 108, 166),
array(83, 69, 62)
);
shuffle($color);
shuffle($color);
shuffle($color);
$colors = array(imagecolorallocate($im, $color[0][0], $color[0][1], $color[0][2]));
$colord = array(imagecolorallocate($im, ($color[0][0] / 1.5), ($color[0][1] / 1.5), ($color[0][2] /
1.5)));
$factorx = array();
$factory = array();
for($i = 0; $i < $total; $i++){
$angle[$i] = (($data[$i] / $data_sum) * 360);
$angle_sum[$i] = array_sum($angle);
$colors[$i] = imagecolorallocate($im, $color[$i][0], $color[$i][1], $color[$i][2]);
$colord[$i] = imagecolorallocate($im, ($color[$i][0] / 1.5), ($color[$i][1] / 1.5), ($color[$i][2]
/ 1.5));
$factorx[$i] = cos(deg2rad(($angle_sum[$i - 1] + $angle_sum[$i]) / 2));
$factory[$i] = sin(deg2rad(($angle_sum[$i - 1] + $angle_sum[$i]) / 2));
}
for($z = 1; $z <= $sz; $z++){
for($i = 0; $i < $total; $i++){
imagefilledarc($im, $cx + ($factorx[$i] * $radius), (($cy + $sz) - $z) + ($factory[$i] * $radius),
$sx, $sy, $angle_sum[$i - 1], $angle_sum[$i], $colord[$i], IMG_ARC_PIE);
}
}
for($i = 0; $i < $total; $i++){
imagefilledarc($im, $cx + ($factorx[$i] * $radius), $cy + ($factory[$i] * $radius), $sx, $sy,
$angle_sum[$i - 1], $angle_sum[$i], $colors[$i], IMG_ARC_PIE);
imagefilledrectangle($im, 900, 50 + ($i * 50 * 2), 950, 100 + ($i * 50 * 2), $colors[$i]);
imagettftext($im, 50, 0, 970, 100 + ($i * 50 * 2), imagecolorallocate($im, 0, 0, 0), $typo,
$keys[$i]);
imagettftext($im, 40, 0, $cx + ($factorx[$i] * ($sx / 4)) - 40, $cy + ($factory[$i] * ($sy / 4)) +
10, imagecolorallocate($im, 0, 0, 0), $typo, $data[$i]);
}
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/function.imagefilledarc.php
Edit -- https://master.php.net/note/edit/113735
Del: integrated -- https://master.php.net/note/delete/113735/integrated
Del: useless -- https://master.php.net/note/delete/113735/useless
Del: bad code -- https://master.php.net/note/delete/113735/bad+code
Del: spam -- https://master.php.net/note/delete/113735/spam
Del: non-english -- https://master.php.net/note/delete/113735/non-english
Del: in docs -- https://master.php.net/note/delete/113735/in+docs
Del: other reasons-- https://master.php.net/note/delete/113735
Reject -- https://master.php.net/note/reject/113735
Search -- https://master.php.net/manage/user-notes.php