elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Tutorial básico de Quickjs


  Mostrar Temas
Páginas: [1]
1  Programación / PHP / problema con las clases para graficar arreglos en torta y lineas en: 17 Julio 2013, 06:08 am
buenas noches:

tengo el siguiente inconveniente.  debo realizar las clases con sus respectivos metodos en php para que se grafique un arreglo de datos en forma de pie o torta y en forma de lineas, ya tengo hechas ambas clases y me muestran en el navegador las imagenes que se crearon, mi problema es que solo me grafican el ultimo dato del arreglo.

soy nueva en php y he hecho todo lo que he encontrado en la web pero no he logrado resolver el problema, ademas que en la web se encuentran son codigos para llamar librerias y en mi caso solo puedo usar las funciones del GD de php5.

<?php

class grafico_barras
{
   private $image;
   private $alto;
   private $ancho;
   private $titulo;
   private $nombre_x;
   private $nombre_y;
   private $rango_ancho;
   private $rango_alto;
   private $color_texto;
   private $color_cuadr;
   private $max_x = 1;
   private $min_x = 0;
   private $max_y = 1;
   private $min_y = 0;
   private $margen_x = 60;
   private $margen_y = 50;
   private $cont = 0;
   private $barra_ancho = 0.2;
   private $color_fondo = array(255, 255, 255);
   private $color = array(
                  array(255, 0, 0), array(128, 0, 128), array(0, 128, 0), array(0, 64, 128), array(0, 128, 40), array(128, 81, 0), array(0, 0, 255), array(128, 0, 68), array(0, 51, 128), array(102, 128, 0), array(87, 0, 128), array(0, 128, 61), array(128, 75, 0), array(69, 0, 128), array(0, 128, 31), array(128, 88, 0), array(65, 0, 128), array(255, 255, 0), array(17, 128, 0), array(0, 89, 128)
               );               
   
   function dibujar($serie)
   {
      $this->image = imagecreate($this->ancho, $this->alto);
      $this->tras_color($this->color_fondo);
      $this->calcRango($serie);
      $this->cuadricula();
      
      Foreach($serie as $x=>$y)
      {
         $this->barras($x, $y);
      }
      
      putenv('GDFONTPATH=' . realpath('.'));
      $fuente = 'Absolut_Pro_Bold_Italic_reduced.ttf';
      $this->color_texto = imagecolorallocate($this->image, 0, 0, 0);
      
      imagefttext($this->image, 12, 90, (($this->margen_x)/2), (((($this->alto)/2)-20)), $this->color_texto, $fuente, $this->nombre_y);
      imagefttext($this->image, 15, 0, (($this->ancho/3)+strlen($this->titulo)), ($this->margen_y/2), $this->color_texto, $fuente, $this->titulo);
      imagefttext($this->image, 12, 0, (($this->ancho/2)-strlen($this->nombre_x)), ($this->alto-($this->margen_y/2)), $this->color_texto, $fuente, $this->nombre_x);
      
      header("content-type: image/png");
      imagepng($this->image);
      imagedestroy($this->image);
      exit;
   }
   
   function tras_color($rgb = null)
   {
      if($rgb == null)
      {
         $rgb = $this->color[$this->cont];
         $this->cont = ($this->cont) < 19 ? ($this->cont+1) : 0;
      }
      
      return imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2]);
   }
   
   function CalcRango($serie)
   {
        foreach($serie as $x=>$y)
        {
            if($x >= $this->max_x) $this->max_x = $x;
         if($x < $this->min_x) $this->min_x = $x;
            if($y >= $this->max_y) $this->max_y = $y;
            if($y < $this->min_y) $this->min_y = $y;
        }
       
        $this->rango_ancho = $this->max_x-$this->min_x;
        $this->rango_alto = $this->max_y-$this->min_y;
   }
   
   function cuadricula($tamano = 20)
   {
       $y = $this->min_y - $tamano;
      
        while($y < ($this->max_y + $tamano))
        {
            $y0 = $this->translateCoordY($y);
         
         $this->color_cuadr = imagecolorallocate($this->image, 191, 191, 191);
            imageline($this->image, 0, $y0, $this->ancho, $y0, $this->color_cuadr);
            $y += $tamano;
        }
   }
   
   function barras($x, $y)
   {
        $p = Array
        (
            ($x-$this->barra_ancho/2), $y,
            ($x+$this->barra_ancho/2), $y,
            ($x+$this->barra_ancho/2), 0,
            ($x-$this->barra_ancho/2), 0
        );
       
        $r = $this->translatePoly($p);
       
        imagefilledpolygon($this->image, $r, sizeof($r)/2, $this->tras_color());
   }
   
   function translateCoordX($x)
   {
      return round($this->margen_x+($this->ancho-2*$this->margen_x)*($x-$this->min_x)/$this->rango_ancho);
   }
   
   function translateCoordY($y)
   {
        return round($this->margen_y-($this->alto-2*$this->margen_y)*($y-$this->max_y)/$this->rango_alto);
   }
   
   function translatePoly($p)
   {
       $r = Array();
       
        for($i=0; $i<sizeof($p); $i+=2)
        {
            $r[] = $this->translateCoordX($p[$i]);
            $r[] = $this->translateCoordY($p[$i+1]);
        }
       
        return $r;
   }
   
   function setTitulo($valor1)
   {
      $this->titulo = $valor1;
   }
   
   function setNombre_x($valor2)
   {
      $this->nombre_x = $valor2;
   }
   
   function setAlto($valor3)
   {
      $this->alto = $valor3;
   }
   
   function setAncho($valor4)
   {
      $this->ancho = $valor4;
   }
   
   function setNombre_y($valor5)
   {
      $this->nombre_y = $valor5;
   }
}

$grafico_barras = new grafico_barras();
$grafico_barras->setTitulo ("Grafia de Barras");
$grafico_barras->setNombre_x ("Meses");
$grafico_barras->setNombre_y ("Ventas en Miles de Pesos");
$grafico_barras->setAlto (600);
$grafico_barras->setAncho (500);
$grafico_barras->dibujar(array(1, 20, 3, 40, 5, 60, 7, 80, 9, 100));

?>


agradezco de antemano toda la ayuda que me puedan brindar.

saludos

Linda.
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines