Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/08/2003, 16:45
Avatar de nuevo
nuevo
 
Fecha de Ingreso: mayo-2003
Ubicación: Spain
Mensajes: 2.009
Antigüedad: 21 años
Puntos: 2
Clase + Objeto para generar simples graficos

hola, comprueben esta classe hacia un objeto.... que genera un simple grafico en barras.... sin usar gd... venga, a ver si os gusta..


Código PHP:
<HTML>
 <HEAD>
   <TITLE>Graficos con HTML</TITLE>
 </HEAD>
 <STYLE TYPE="text/css">
     TD{
        text-align:center;
    font-family:"Verdana","Courier New";
    font-size:12px;
     }
     
     TD.titulo{
    font-size:20px;
    font-weight:bold;
    color:orange;
     }
 </STYLE>
 <BODY>
   <CENTER>
     <H2>Graficos<I></I></H2>
     <?php

       
class barra{
           var 
$color;
       var 
$alto;
       var 
$ancho;
       var 
$nombre;

       function 
barra($nombre,$color,$alto,$ancho=50){
          
$this->nombre=$nombre;
          
$this->color=$color;
          
$this->alto=$alto;
          
$this->ancho=$ancho;
       }
       }

       class 
graficaBarras{
       var 
$elementos;
           var 
$titulo;

           function 
graficaBarras(){
           
$this->elementos=array();
           
$this->titulo="";
           }

           function 
fijarValor($nombre,$color,$alto,$ancho=50){
           
$barra = new barra($nombre,$color,$alto,$ancho);
           
$this->elementos[]=$barra;
       }

           function 
fijarTitulo($titulo){
           
$this->titulo=$titulo;
       }

           function 
dibuja(){
          if(
count($this->elementos)==0) return 0;
          echo 
"<TABLE BORDER='0'>\n";
          if(
$this->titulo){
               echo 
"<TR><TD CLASS='titulo'>$this->titulo</TD></TR>";
             echo 
"<TR><TD></TD></TR>\n";
          }
          echo 
"<TR><TD>";
          echo 
"<DIV>\n";
          for(
$i=0;$i<count($this->elementos);$i++){
                echo 
"<SPAN STYLE='";
          echo 
"width:".$this->elementos[$i]->ancho."; ";
          echo 
"height:".$this->elementos[$i]->alto."; ";
          echo 
"background-color:".$this->elementos[$i]->color.";";
          echo 
"'>".$this->elementos[$i]->alto."</SPAN>\n";
          }
          echo 
"</DIV></TD></TR>\n";
          echo 
"<TR><TD><HR></TD></TR>\n";
          echo 
"<TR><TD CLASS='pie'>";
          echo 
"<DIV>\n";
          for(
$i=0;$i<count($this->elementos);$i++){
                echo 
"<SPAN STYLE='";
          echo 
"width:".$this->elementos[$i]->ancho.";'>";
                echo 
$this->elementos[$i]->nombre."</SPAN>\n";
          }
          echo 
"</DIV></TD></TR>\n";
          echo 
"</TABLE><BR>\n";
           }

      }

        
$migrafica1=new graficaBarras;
    
$migrafica1->fijarValor("dato1","red","100");
    
$migrafica1->fijarValor("dato2","green","150");
    
$migrafica1->fijarValor("dato3","blue","80");
    
$migrafica1->fijarValor("dato4","silver","130");
    
$migrafica1->fijarTitulo("Gráfica 1");
        
$migrafica1->dibuja();
    
        
$migrafica2=new graficaBarras;
    
$migrafica2->fijarValor("a","red","80","30");
    
$migrafica2->fijarValor("b","green","50","30");
    
$migrafica2->fijarValor("c","blue","35","30");
    
$migrafica2->fijarValor("d","silver","30","30");
    
$migrafica2->fijarValor("e","yellow","70","30");
    
$migrafica2->fijarTitulo("Gráfica 2");
        
$migrafica2->dibuja();
     
?>
   </CENTER>
 </BODY>
</HTML>
lo pongo pq me han llegado varios mensajes privados pidiendo un ejemplo como el de mi web....
__________________
3w.valenciadjs.com
3w.laislatv.com