kadreg profil: Utilisateur | show me the code ...
Voici un exemple qui marche, qui fait un camembert à partir d'un tableau attribut/valeur, ca te donnera peut être une idée :
Code :
- function createCamembert ($filename, $values) {
- $width = 400;
- $height = 200;
- $graph = imageCreate ($width, $height);
- $white = ImageColorAllocate ($graph, 255,255,255);
- $black = ImageColorAllocate ($graph, 0,0,0);
- $fond = ImageColorAllocate ($graph, 245, 245, 245);
- imagefill ($graph, 0, 0, $fond);
- $total = 0;
- $xLegendBegin = ($width - $height + 50);
- $yLegend = 20;
- $colors = array (ImageColorAllocate ($graph, 255,0,0),
- ImageColorAllocate ($graph, 255,0,0),
- ImageColorAllocate ($graph, 0,255,0),
- ImageColorAllocate ($graph, 0,0,255),
- ImageColorAllocate ($graph, 0,255,255),
- ImageColorAllocate ($graph, 255,0,255),
- ImageColorAllocate ($graph, 255,255,0),
- ImageColorAllocate ($graph, 255,128,64),
- ImageColorAllocate ($graph, 128,64,255),
- ImageColorAllocate ($graph, 64,255,128),
- ImageColorAllocate ($graph, 64,128,255),
- ImageColorAllocate ($graph, 255,64,128));
- while (list ($name, $value) = each ($values)) {
- $total += $value;
- }
- reset ($values);
- $begin = 0;
- $end = 0;
- $radius = $height/2 - 10;
- imageline ($graph, $height/2, $height/2, $height/2 + $radius, $height/2, $black);
- imagearc ($graph, $height/2, $height/2, $radius * 2, $radius * 2, 0, 360, $black);
- reset ($colors);
- while (list ($name, $value) = each ($values)) {
- $begin = $end;
- $end = $begin + (($value * 360) / $total);
- $xLineStart = $height / 2;
- $yLineStart = $height / 2;
- $xLineEnd = $height/2 + ($radius * cos (deg2rad ($end)));
- $yLineEnd = $height/2 + ($radius * sin (deg2rad ($end)));
- imageline ($graph, $xLineStart, $yLineStart,
- $xLineEnd, $yLineEnd,
- $black);
- $color = next ($colors);
- $xColorPoint = $height/2 + (($radius/2) * cos (deg2rad (($end + $begin)/ 2)));
- $yColorPoint = $height/2 + (($radius/2) * sin (deg2rad (($end + $begin)/ 2)));
- /* on ne fill que si end - begin > 5° */
- if (abs($end - $begin) > 5){
- imagefilltoborder ($graph, $xColorPoint, $yColorPoint, $black, $color);
- }
- /* la legende maintenant */
- imagefilledrectangle ($graph, $xLegendBegin, $yLegend, $xLegendBegin + 10, $yLegend + 10, $color);
- imagestring ($graph, 2, $xLegendBegin + 20, $yLegend, $name, $black);
- $yLegend += 20;
- }
- unlink ($filename);
- imageGif ($graph, $filename);
- }
|
---------------
brisez les rêves des gens, il en restera toujours quelque chose... -- laissez moi troller sur discu !
|