<?php
/* ========================================== 
 * Filename:    diagram_gd.php
 * Author:        Frederik Sørensen. Contact: frederik@patch.dk 
 * License:     MIT http://www.opensource.org/licenses/mit-license.php
 *                                              
 * Description:                                  
 * Generates a png image. Makes a pie chart from the percent data in the array
 * $data. The sum of the values in the array must be 100.
 * 
 * Version:        1.0    
 * History:     30/1/2005 First release 
 * 
 * ========================================== */

$data = array('10''25''50''15');

// create image
$image imagecreate(200200);

// allocate some colors, we can only plot the amount of data that we have color for, 
// ie. we have to 4 data items so we are going to use, grey, navy, red and green all our colors
// You could make code that generate the color. But since this is only an eksample we don't
$white      imagecolorallocate($image0xFF0xFF0xFF); // white
$color[]    = imagecolorallocate($image0xC00xC00xC0); // grey
$color[]    = imagecolorallocate($image0x900x900x90); // darkgrey
$color[]    = imagecolorallocate($image0x000x000x80); // navy
$color[]    = imagecolorallocate($image0x000x000x50); // darknavy
$color[]    = imagecolorallocate($image0xFF0x000x00); // red
$color[]    = imagecolorallocate($image0x900x000x00); // darkred
$color[]    = imagecolorallocate($image0x000xFF0x00); // green
$color[]    = imagecolorallocate($image0x000xCC0x00); // darkgreen

// make the 3D effect
$start_degree 0;
for(
$i 110$i >= 100$i--){
    
$n 1;
    foreach(
$data as $data2){
        
$degree 360*$data2/100;
        
imagefilledarc($image100$i15075$start_degree$start_degree+$degree$color[$n], IMG_ARC_PIE);
        
$start_degree += $degree;
        
$n += 2;
    }
}

// make plot
$start_degree 0;
$n 0;
foreach(
$data as $data2){
    
$degree 360*$data2/100;
    
imagefilledarc($image10010015075$start_degree$start_degree+$degree$color[$n], IMG_ARC_PIE);
    
$start_degree += $degree;
    
$n += 2;
}


// flush image
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>