note 89216 added to function.imagefilledarc

From: Date: Thu, 26 Feb 2009 17:31:00 +0000
Subject: note 89216 added to function.imagefilledarc
Groups: php.notes 
Request: Send a blank email to php-notes+get-151177@lists.php.net to get a copy of this message
The code below uses colors from "hans at lintoo dot dk"'s note. It delivers pie charts with labels: <?php $bright_list = array( array(255, 203, 3), array(220, 101, 29), array(189, 24, 51), array(214, 0, 127), array(98, 1, 96), array(0, 62, 136), array(0, 102, 179), array(0, 145, 195), array(0, 115, 106), array(178, 210, 52), array(137, 91, 74), array(82, 56, 47) ); $dark_list = array( array(205, 153, 0), array(170, 51, 0), array(139, 0, 1), array(164, 0, 77), array(48, 0, 46), array(0, 12, 86), array(0, 52, 129), array(0, 95, 145), array(0, 65, 56), array(128, 160, 2), array(87, 41, 24), array(32, 6, 0) ); $data = array(); $angle = array(); $title = array(); $i = 0; foreach( $_GET as $key => $value ) { $data[$i] = intval($value); $title[$i++] = str_replace("_"," ",strval($key)); } $sum = array_sum($data); if( $sum == 0 ) { ++ $sum; } $count = count($data); for( $i = 0; $i < $count; ++ $i ) { $angle[$i] = floor($data[$i]/$sum*360); if( $angle[$i] == 0 ) { ++ $angle[$i]; } } $sum_angle = array_sum($angle); if( $sum_angle < 360 ) { $angle[0]+=360-$sum_angle; } $height = $count*34; if( $height < 180 ) { $height = 180; } $im = imagecreate (350, $height); $background = imagecolorallocate($im, 226, 226, 226); $border = imagecolorallocate($im,97,97,97); $font_color = imagecolorallocate($im,0,0,0); $font = 'yourfont.ttf'; $bright = array(); foreach( $bright_list as $c ) { $bright[] = imagecolorallocate($im,$c[0],$c[1],$c[2]); } $dark = array(); foreach( $dark_list as $c ) { $dark[] = imagecolorallocate($im,$c[0],$c[1],$c[2]); } $tmp = 0; for( $i =0; $i < $count; ++ $i ) { for( $j = 100; $j > 90; -- $j ) { imagefilledarc($im, 100, $j, 180, 120, $tmp, $tmp+$angle[$i], $dark[$i], IMG_ARC_PIE); } $tmp += $angle[$i]; } $tmp = 0; for( $i =0; $i < $count; ++ $i ) { imagefilledarc($im, 100, 90, 180, 120, $tmp, $tmp+$angle[$i], $bright[$i], IMG_ARC_PIE); $tmp += $angle[$i]; } for( $i = 0; $i < $count; ++ $i ) { imagefilledrectangle($im, 209, 19+($i*30), 231, 41+($i*30), $border); imagefilledrectangle($im, 210, 20+($i*30), 230, 40+($i*30), $bright[$i]); imagefttext($im, 11, 0, 240, 34+($i*30), $font_color, $font, $title[$i]); } header('Content-type: image/png'); imagepng($im); imagedestroy($im); ?> try 'pie.php?foo=3&bar=4&baz=6' ---- Server IP: 82.177.164.100 Probable Submitter: 85.193.250.141 ---- Manual Page -- http://www.php.net/manual/en/function.imagefilledarc.php Edit -- https://master.php.net/note/edit/89216 Del: integrated -- https://master.php.net/note/delete/89216/integrated Del: useless -- https://master.php.net/note/delete/89216/useless Del: bad code -- https://master.php.net/note/delete/89216/bad+code Del: spam -- https://master.php.net/note/delete/89216/spam Del: non-english -- https://master.php.net/note/delete/89216/non-english Del: in docs -- https://master.php.net/note/delete/89216/in+docs Del: other reasons-- https://master.php.net/note/delete/89216 Reject -- https://master.php.net/note/reject/89216 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#151177) next »