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>
