Location: PHPKode > projects > SureInvoice > sureinvoice-1.0/graph.php
<?
require_once('includes/common.php');
checkLogin();

require_once('includes/SI_Project.php');
require_once('includes/SI_Company.php');
require_once('includes/SI_TaskActivity.php');
require_once('includes/SI_Task.php');
require_once("jpgraph.php");
require_once("jpgraph_pie.php");
require_once("jpgraph_pie3d.php");

// Get the data
$activity = new SI_TaskActivity();
$activities = $activity->find($_REQUEST['start_ts'], $_REQUEST['end_ts'], $_REQUEST['resource_id'], $_REQUEST['company_id'], $_REQUEST['billable']);
if(count($activities) <= 0){
	$error_msg .= "Error getting report data!\n";
	debug_message($activity->getLastError());
}		

$data = array();
$labels = array();
foreach($activities as $act){
	if($_REQUEST['type'] == 'company'){
		$title = "Time by Company";
		$data[$act->company] += ($act->end_ts - $act->start_ts);
		$labels[$act->company] = $act->company;
	}else if($_REQUEST['type'] == 'project'){
		$title = "Time by Project";
		$data[$act->project] += ($act->end_ts - $act->start_ts);
		$labels[$act->project] = $act->project;	
	}else{
		$error_msg .= "Invalid report type!\n";
	}
}
$data_array = array();
$label_array = array();
foreach($data as $key => $item){
	$data_array[] = $item;
	$label_array[] = $labels[$key];
}
	
debug_message(print_r($data_array, $label_array, TRUE));
// Create the Pie Graph.
$graph = new PieGraph(500,325);
$graph->SetShadow();

// Set A title for the plot
$graph->title->Set($title);
$graph->title->SetFont(FF_VERDANA,FS_BOLD,18); 
$graph->title->SetColor("darkblue");
//$graph->legend->Pos(0.1,0.2);

// Create pie plot
$p1 = new PiePlot3d($data_array);
$p1->SetTheme("earth");
$p1->SetCenter(0.35, 0.6);
$p1->SetAngle(30);
$p1->SetFont(FF_ARIAL,FS_NORMAL,12);
$p1->SetLegends($label_array);

$graph->Add($p1);
$graph->Stroke();


?>
Return current item: SureInvoice