"Stage 1", "date_start" => "7/1/2007", "date_end" => "7/1/2007", 'color' => 'CED0B0' ); $events_array[1] = array( 'stage' => "Stage 2", "date_start" => "7/3/2007", "date_end" => "7/12/2007", 'color' => 'B2D0B0' ); $events_array[2] = array( 'stage' => "Stage 3", "date_start" => "7/9/2007", "date_end" => "7/15/2007", 'color' => '8589BB' ); $events_array[3] = array( 'stage' => "Stage 4", "date_start" => "7/16/2007", "date_end" => "7/18/2007", 'color' => 'B885BB' ); $events_array[4] = array( 'stage' => "Stage 5", "date_start" => "7/17/2007", "date_end" => "7/19/2007", 'color' => 'BB858D' ); $events_array[5] = array( 'stage' => "Stage 6", "date_start" => "7/20/2007", "date_end" => "7/25/2007", 'color' => 'CED0B0' ); $events_array[6] = array( 'stage' => "Stage 7", "date_start" => "7/24/2007", "date_end" => "7/27/2007", 'color' => 'B2D0B0' ); $events_array[7] = array( 'stage' => "Stage 8", "date_start" => "7/27/2007", "date_end" => "7/30/2007", 'color' => '8589BB' ); $events_array[8] = array( 'stage' => "Stage 9", "date_start" => "7/28/2007", "date_end" => "7/30/2007", 'color' => '8589BB' ); $events_array[9] = array( 'stage' => "Stage 10", "date_start" => "7/29/2007", "date_end" => "8/1/2007", 'color' => 'B885BB' ); $data_for_chart = ''; foreach ( $events_array as $key => $value ){ $date_start_u = date('U', strtotime ($value['date_start']) ); $date_end_u = date('U', strtotime ($value['date_end']) ); $data_for_chart[$key]['label'] = $value['stage']; $data_for_chart[$key]['value'] = (( $date_end_u - $date_start_u ) / 86400 ) + 1; } //get total_value $total_value = ''; foreach ( $data_for_chart as $key => $value ) { $total_value = $total_value + $value['value']; } // create image $image = imagecreatetruecolor(1400, 1400); // allocate some solors $color['white']= imagecolorallocate($image, 0xFF, 0xFF, 0xFF); $color[0] = imagecolorallocate($image, 250, 0, 0); // $color[1] = imagecolorallocate($image, 255, 126, 0); $color[2] = imagecolorallocate($image, 255, 255, 0); $color[3] = imagecolorallocate($image, 0, 255, 0); $color[4] = imagecolorallocate($image, 0, 255, 255); $color[5] = imagecolorallocate($image, 0, 0, 255); $color[6] = imagecolorallocate($image, 180, 0, 250); $color[7] = imagecolorallocate($image, 255, 0, 180); $color[8] = imagecolorallocate($image, 192, 197, 131); $color[9] = imagecolorallocate($image, 80, 80, 80); imagefill ( $image, 0, 0, $color['white'] ); $i = 0; $rad = 0; foreach ( $data_for_chart as $key => $value ) { //calculate the percentage of total value $rad_begin = $rad; $rad = $rad + ( $value['value'] * 360 ) / $total_value ; //echo "rad = $rad label = ".$value['label']. "value = ".$value['value']."
"; imagefilledarc($image, 300, 300, 500, 500, $rad_begin, $rad, $color[$i], IMG_ARC_PIE); // Waterfall of point sizes to see what Freetype 2's autohinting looks like: // //$t = (( $rad - $rad_begin )/2) + $rad_begin; $t = (($rad - $rad_begin)/2) + $rad_begin; //x(t) = r cos(t) + j //y(t) = r sin(t) + k $per = intval( ($value['value'] * 100 )/$total_value ); // beginings of adding labels next to each pie piece //$x_coor = intval( (200 * cos( deg2rad($t) ) ) + 500 ); //$y_coor = intval( (200 * sin( deg2rad($t) ) ) + 500 ); //ImageFtText($image,20,0,$y_coor,$x_coor,$forecolor,'./fonts/Arena Condensed.ttf', $value['label']." ".$value['value']." days", array("linespacing" => .90)); imagefilledrectangle ($image, 600, 75 + ($i*50), 650, 95 + (($i*50) + 25), $color[$i] ); ImageFtText($image,30,0,675,112 + ($i*50),$forecolor,'../fonts/Arena Condensed.ttf', $value['label']." (".$per ."%)", array("linespacing" => 10.0)); $i = $i+1; } imageantialias ( $image, 1 ); $destImage = imagecreatetruecolor(400,200); imagecopyresampled($destImage,$image,0,0,0,0,400,200,1400,700); // flush image header('Content-type: image/png'); imagepng($destImage); imagedestroy($image); imagedestroy($destImage); ?>