Location: PHPKode > projects > PHP Report > phpreport-v1.0/GraficoRelVisu.php
<?
/***********************************************************************************/
/*                                 PHP Report                                      */
/*                                                                                 */
/* Copyright (c) 2005 by Daniela Toniolo, Leonardo Galv√£o and Marli Carneiro       */
/*                                                                                 */
/* This is a free software. You can redistribute it and/or modify it under the     */
/* terms of the GNU General Public License.                                        */
/***********************************************************************************/

include("classes/Class_Conexao.php");
function Grafico(){
	$base = $_GET['base'];
	$sqlselect = $_GET['sqlselect'];
	$from_gra = $_GET['from_gra'];
	$sqlwhere = $_GET['sqlwhere_gra'];
	$tipo = $_GET['tipo'];
	$titulo = $_GET['titulo'];
	$tabelax = $_GET['tabelax'];
	$campox = $_GET['campox'];
	$tabelay = $_GET['tabelay'];
	$campoy = $_GET['campoy'];
	$legendax = $_GET['legendax'];
	$legenday = $_GET['legenday'];
	
	$sqlorder = stripslashes($sqlorder);
	$sqlwhere = stripslashes($sqlwhere);
	$from_gra = stripslashes($from_gra);
	$sqlselect = stripslashes($sqlselect);
	$sqlwhere = str_replace("[[aspas]]","'",$sqlwhere);
	
	$array_x = null;
	$array_y = null;
	$conecta = Conexao::ConectaRel($base);
	$stringsql_x = "SELECT `".$tabelax."`.`".$campox."` AS EIXOX".$from_gra.$sqlwhere." GROUP BY `".$tabelax."`.`".$campox."`";
	$result_x = $conecta->query($stringsql_x);
	if (DB::isError($result_x)) die ($result_x->getDebugInfo());
	$rows_x = $result_x->numRows();
	if ($rows_x > 0){
		while($i = $result_x->fetchRow(DB_FETCHMODE_OBJECT)){
			$valor_x = $i->EIXOX;
			$valor_x = addslashes($valor_x);
			if($tipo == 3){
				if (strlen($valor_x) <= 17) $array_x[] = " ".$valor_x; else $array_x[] = " ".(substr($valor_x, 0, 17));
			} else {
				if (strlen($valor_x) <= 13) $array_x[] = " ".$valor_x; else $array_x[] = " ".(substr($valor_x, 0, 13));
			}
			if ($sqlwhere==null) $where = " WHERE `".$tabelax."`.`".$campox."`='".$valor_x."'";
			else $where = $sqlwhere." AND `".$tabelax."`.`".$campox."`='".$valor_x."'";
			$stringsql_y = "SELECT SUM(`".$tabelay."`.`".$campoy."`) AS EIXOY".$from_gra.$where;
			$result_y = $conecta->query($stringsql_y);
			if (DB::isError($result_y)) die ($result_y->getDebugInfo());
			$rows_y = $result_y->numRows();
			if ($rows_y > 0){
				while($j = $result_y->fetchRow(DB_FETCHMODE_OBJECT)){
					$valor_y = $j->EIXOY;
					$array_y[] = $valor_y;
				}
			}
		}
	}
	include ("scripts/jpgraph/jpgraph.php");
	include ("scripts/jpgraph/jpgraph_line.php");
	include ("scripts/jpgraph/jpgraph_bar.php");
	include ("scripts/jpgraph/jpgraph_pie.php");
	include ("scripts/jpgraph/jpgraph_pie3d.php");

		if($tipo == 3) $gJpgBrandTiming=true;
		
		if($tipo == 3) $graph = new PieGraph(550,300,'auto'); else $graph = new Graph(550,300,'auto');
	
		$graph->SetShadow();
		$graph->SetScale("textlin");
		
		$graph->img->SetMargin(45,30,40,90);
	
		$graph->title->SetFont(FF_FONT1,FS_BOLD);
		$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
		$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
		$graph->xaxis->SetLabelAngle(90);
	
	if($tipo == 2){
		$lineplot = new LinePlot($array_y); 
		$lineplot->SetColor("blue");
		$graph->title->Set($titulo);
		$graph->xaxis->SetTickLabels($array_x);
		$graph->xaxis->title->Set($legendax);
		$graph->yaxis->title->Set($legenday);
		$graph->Add($lineplot);
		$graph->Stroke();
	}
	if($tipo == 1){
		$BarPlot=new BarPlot($array_y);
		$BarPlot->SetColor("blue");
		$graph->title->Set($titulo);
		$graph->xaxis->SetTickLabels($array_x);
		$graph->xaxis->title->Set($legendax);
		$graph->yaxis->title->Set($legenday);
		$graph->legend->Pos(0.03,0.5,"right","center");
		$graph->Add($BarPlot);
		$graph->Stroke();
	}
	if($tipo == 3){
			$array_x2 = array_reverse($array_x);
			$p1 = new PiePlot3D($array_y);
			$graph->title->Set($titulo); 
			$p1->SetLegends($array_x2);
			$graph->legend->Pos(0.02,0.02);
			$p1->SetCenter(0.35,0.5);
			$p1->SetLabelType(0);
			$graph->Add($p1);
			$graph->StrokeCSIM('GraficoRelVisu.php');
	}
}
Grafico();
?>
Return current item: PHP Report