Location: PHPKode > scripts > phpchartPlus > phpchartplus/Sources/PieChart.php
<?php

/*
**************************************************
Class: PieChart.php
**************************************************
Author: Tsiavos Chris <hide@address.com>
Date: October 2004
**************************************************/

/**
*Includes the Rectangle class
*/
require_once("Circle.php");

/**
*Includes the chart base class
*/
require_once("Chart.php");

/**
*PieChart generation
*/
class PieChart extends Chart {

	protected function draw_Grids() { return; }
	
	protected function draw() {
	
		$ItemNames=$this->DataParser_->get_GroupItemsName();
		$ItemColors=$this->ConfigParser_->get_LegendColors();
		$GroupNames=$this->DataParser_->get_GroupsName();	
		$ChartData=array();
		$Pie=array();
		$ShadePie=array();
		
		$PieNum=$this->DataParser_->get_GroupsNum();
		$PieArea=$this->Area_xsize-2*5-(3*($PieNum-1));
		$PieWidth=$PieArea/$PieNum;
		
		if ($PieWidth>$this->Area_ysize)
		{
			$PieHeight=$this->Area_ysize-5;
			$PieWidth=$PieHeight;
		}
		else
			$PieHeight=$PieWidth;
			
		$PieCenterYPos=$this->ConfigParser_->get_ChartVmargin()+$this->Area_ysize/2;
		$PieUseAntialias=$this->ConfigParser_->get_ChartUseAntialias();
					
		for ($group=0;$group<$this->DataParser_->get_GroupsNum();$group++) {
			
			$CenterXPos=$this->ConfigParser_->get_ChartHmargin()+5+(3*$group)+$PieWidth*$group+($PieWidth/2);	
			
			$FontColor=$this->ConfigParser_->get_FontColor();
			$FontMetrics=$this->Font_->get_FontMetrics($GroupNames[$group]);
			$GroupName_YPos=$this->ConfigParser_->get_ChartVmargin()+$this->Area_ysize+2;
			$GroupName_XPos=$CenterXPos-($FontMetrics["FontWidth"]/2);
			$this->Font_->draw_String($GroupName_XPos,$GroupName_YPos,$GroupNames[$group],$FontColor);
			
			$Pie[$group]=new Circle($this->Chart_Image,$this->ColorAllocator_,$PieUseAntialias,$CenterXPos,$PieCenterYPos,$PieWidth,$PieHeight);
		}
		
		for ($item=0;$item<$this->DataParser_->get_GroupItemsNum();$item++) {
			
			$ChartData=$this->DataParser_->get_ItemFromGroups($ItemNames[$item]);
			
			for ($group=0;$group<$this->DataParser_->get_GroupsNum();$group++) {
				
				$ChunkColor=explode(",",$ItemColors[$item]);
				$ChunkValue=(100*$ChartData[$group])/$this->ConfigParser_->get_GridMaxValue();
				$ChunkAngle=360*($ChunkValue/100);
						
				$Chunk=new Chunk();
				$Chunk->set_Angle($ChunkAngle);
				$Chunk->set_Color($ChunkColor[0],$ChunkColor[1]);
				$Chunk->set_Caption($this->Font_,$ChunkValue." %",$this->ConfigParser_->get_GridColor());
				$Pie[$group]->addChunk($Chunk);
			}	
		}
		
		for ($group=0;$group<$this->DataParser_->get_GroupsNum();$group++) {
			$Pie[$group]->draw_Filled();
		 	$Pie[$group]->draw($this->ConfigParser_->get_GridColor());
		 }
	}

}

?>
Return current item: phpchartPlus