<?php
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_odo.php');
include('../clases/clase.conexion.php');
include('../funciones/variables.php');
$var = VarServer("MYSQLI");
$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);

$sql = "call spQuery_Avance_Ventas_Proveedor('2011','11','', '2011-11-01','2011-11-30');";
$obj->AbrirConexion();
$rs = $obj->Query($sql);
$obj->CerrarConexion();
$acaptions = NULL;

// Create a new odometer graph (width=250, height=200 pixels)
$graph = new OdoGraph(600,800);
$graph->title->Set('Example with scale indicators');
$odo = array();

$i = 0;
$varArrayReal = array();
$varArrayTend = array();
while($fila = $obj->FetchArray($rs)) {
	if($fila["META"]<>"" && $fila["META"]>0) {
		$varTitu = $fila["LINEA"]."\nAvance Real : ".number_format($fila["PORC_AVANCE"],2,".",",")."%";	
		$odo[$i] =new Odometer();
		//$odo[$i]->SetColor("lightyellow");
		$odo[$i]->needle->Set($fila["PORC_AVANCE"]);
		//$odo[$i]->needle->SetStyle(NEEDLE_STYLE_ENDARROW, NEEDLE_ARROW_LL);
		//$odo[$i]->caption->SetFont(FF_FONT1,FS_BOLD);
		$odo[$i]->caption->Set($varTitu);
		$odo[$i]->AddIndication(0,40,'red');
		$odo[$i]->AddIndication(40,60,'orange');
		$odo[$i]->AddIndication(60,80,'yellow');
		$odo[$i]->AddIndication(80,90,'green:0.7');
		$odo[$i]->AddIndication(90,100,'green:0.9');		
		$varArrayReal[$i] = $odo[$i];
		
		$varTitu = $fila["LINEA"]."\nTendencia : ".number_format($fila["PORC_TENDENCIA"],2,".",",")."%";	
		$odo[$i] =new Odometer();
		$odo[$i]->SetColor("lightyellow");
		$odo[$i]->needle->Set($fila["PORC_TENDENCIA"]);
		//$odo[$i]->needle->SetStyle(NEEDLE_STYLE_ENDARROW, NEEDLE_ARROW_LL);
		//$odo[$i]->caption->SetFont(FF_FONT1,FS_BOLD);
		$odo[$i]->caption->Set($varTitu);
		$odo[$i]->AddIndication(0,40,'red');
		$odo[$i]->AddIndication(40,60,'orange');
		$odo[$i]->AddIndication(60,80,'yellow');
		$odo[$i]->AddIndication(80,90,'green:0.7');
		$odo[$i]->AddIndication(90,100,'green:0.9');		
		$varArrayTend[$i] = $odo[$i];
		$i++;
		}
	}

/*
$astyles = array(
    NEEDLE_ARROW_LL,NEEDLE_ARROW_SM,NEEDLE_ARROW_SL,
    NEEDLE_ARROW_MS,NEEDLE_ARROW_MM, NEEDLE_ARROW_ML,
    NEEDLE_ARROW_LS, NEEDLE_ARROW_LM, NEEDLE_ARROW_LL
  -  );
  */
//$acaptions = array(
 //   'SS','SM','SL','MS','MM','ML','LS','LM','LL'
//);
/*
for($i = 0; $i < 9; ++$i ) {
    $odo[$i] =     new Odometer();
    $odo[$i]->SetColor("lightyellow");
    $odo[$i]->needle->Set(75);
    $odo[$i]->needle->SetStyle(NEEDLE_STYLE_ENDARROW, $astyles[$i]);
    $odo[$i]->caption->SetFont(FF_FONT1,FS_BOLD);
    $odo[$i]->caption->Set($acaptions[$i]);
	$odo[$i]->AddIndication(0,40,'red');
    $odo[$i]->AddIndication(40,60,'orange');
	$odo[$i]->AddIndication(60,80,'yellow');
    $odo[$i]->AddIndication(80,90,'green:0.7');
	$odo[$i]->AddIndication(90,100,'green:0.9');


}
*/
//$row1 = new LayoutHor( array($odo[0],$odo[1],$odo[2]) );
//$row2 = new LayoutHor( array($odo[3],$odo[4],$odo[5]) );
//$row3 = new LayoutHor( array($odo[6],$odo[7],$odo[8]) );
//$col1 = new LayoutVert( array($row1,$row2,$row3) );
//$row1 = new LayoutVert( array($odo[0],$odo[1],$odo[2],$odo[3],$odo[4]) );

$ver1 = new LayoutVert( $varArrayReal);
$ver2 = new LayoutVert( $varArrayTend);
$row1 = new LayoutHor(array($ver1,$ver2) );
// Add the odometer to the graph
$graph->Add($row1);

// ... and finally stroke and stream the image back to the browser
$graph->Stroke();
?>