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

 

 


Tema destacado: Usando Git para manipular el directorio de trabajo, el índice y commits (segunda parte)


  Mostrar Mensajes
Páginas: [1]
1  Programación / PHP / Re: problema con las clases para graficar arreglos en torta y lineas en: 17 Julio 2013, 18:15 pm
en mi navegador si sale.... uno de los errores debe ser la fuente que utilizo para los titulos...colocale cualquiera con extension .ttf y ahi se te soluciona muchisimos errores... de resto debe aparecer como en mi navegador, solo sale el titulo y un circulo de un solo color, el cual pertenece al ultimo dato del arreglo... ese es el problema, que solo me esta graficando el ultimo dato.

ten en cuenta, aunque no se si interfiere demasaido, que yo uso php5.

muchas gracias por todo.

Linda.
2  Programación / PHP / Re: problema con las clases para graficar arreglos en torta y lineas en: 17 Julio 2013, 16:59 pm
me disculpo, coloque el codigo equivocado... es que enseguida colocare es del grafico de torta

<?php

class grafico_torta
{
   private $image;
   private $ancho;
   private $alto;
   private $color_texto;
   private $titulo;
   private $valor_porc;
   private $valor_grad;
   private $valor_tot;
   private $inicio = 0;
   private $suma = 0;
   private $alto_torta;
   private $ancho_torta;
   private $ancho_graf;
   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 $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);
      
      Foreach($serie as $x=>$y)
      {
         $this->torta($y);
      }
      
      $this->color_texto = imagecolorallocate($this->image, 0, 0, 0);
      putenv('GDFONTPATH=' . realpath('.'));
      $fuente = 'Absolut_Pro_Bold_Italic_reduced.ttf';
      
      imagefttext($this->image, 15, 0, (($this->ancho/3)+strlen($this->titulo)), ($this->margen_y/2), $this->color_texto, $fuente, $this->titulo);
      
      header("content-type: image/png");
      imagepng($this->image);
      imagedestroy($this->image);
   }
   
   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 torta($y)
   {   
//3102089309 - 3134085989 carlos jose sanchez      
      $this->alto_torta = $this->alto / 2;
      $this->ancho_torta = $this->ancho / 2;
      $this->ancho_graf = ($this->ancho / 4)*1.5;
      $this->alto_graf = ($this->alto / 4)*1.5;
      
      if($this->inicio == 0)
      {
         $final = $this->grados($y);
         imagefilledarc($this->image, $this->ancho_torta, $this->alto_torta, $this->ancho_graf, $this->alto_graf, $this->inicio, $final, $this->tras_color(), IMG_ARC_PIE);
      }
      else
      {
         imagefilledarc($this->image, $this->ancho_torta, $this->alto_torta, $this->ancho_graf, $this->alto_graf, $this->inicio, $final, $this->tras_color(), IMG_ARC_PIE);
      }
      $this->inicio = $final;
   }
   
   function grados($y)
   {
      $this->valor_grad = (($y*360)/$this->suma_total($serie));
   }   
      
   function suma_total($serie)
   {
      foreach($serie as $x=>$y)
      {
         if($x == 0)
         {
            $this->valor_tot = $y;
         }
         else
         {
            $this->valor_tot = $this->valor_tot + $y;
         }
      }
      
      return $this->valor_tot;
   }
/*      
   function porcentaje($serie)
   {
      foreach($serie as $x=>$y)
      {
         $valor_porc = (($y*100)/$this->suma_total);
      }
      return $valor_porc;
   }
*/   
   function setAncho($valor1)
   {
      $this->ancho = $valor1;
   }
   
   function setAlto($valor2)
   {
      $this->alto = $valor2;
   }
   
   function setTitulo($valor3)
   {
      $this->titulo = $valor3;
   }
}

$grafico_torta = new grafico_torta();
$grafico_torta->setAncho(600);
$grafico_torta->setAlto(600);
$grafico_torta->setTitulo ("GRAFICA DE TORTA");
$grafico_torta->dibujar(array(80, 2));
?>


muchas gracias
3  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