la librería se llama jpgraph
la puedes obtener desde
bueno vamos al grano, la idea que quiero presentar es : obtener datos desde una BD Mysql
y poder realizar una estadística
las variables donde se guarda los puntos son :
$datay1,$datay2,$datay3, $datayN, etc ...
bueno para que me entiendan coloco el code de uno de los ejemplos que trae la librería:
SetScale("textlin");
$graph->SetMargin(200,200,200,200);
$theme_class=new VividTheme;
$graph->yaxis->HideZeroLabel();
$graph->ygrid->SetFill(true,'#EFEFEF@0.5','#BBCCFF@0.5');
$graph->xgrid->Show();
$graph->SetTheme($theme_class);
$graph->img->SetMargin(80,30,30,40);
$graph->title->Set('Mensajes BPServer');
$graph->yaxis->title->SetFont(FF_FONT2,FS_BOLD);
$graph->xaxis->title->Set('Hora');
$graph->yaxis->title->Set('Mensajes'); // nombre del eje Y plano cartesiano
$graph->SetBox(false);
$graph->yaxis->title->SetFont( FF_FONT1 , FS_BOLD );
$graph->xaxis->title->SetFont( FF_FONT1 , FS_BOLD );
$graph->img->SetAntiAliasing(true);
$graph->yaxis->HideZeroLabel(true);
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);
$graph->xgrid->Show();
$graph->xgrid->SetLineStyle("solid");
$graph->xaxis->SetTickLabels(array('06:00','','08:00','','10:00','','12:00','','14:00','','16:00','','18:00','','20:00','','22:00'));
$graph->xgrid->SetColor('#E3E3E3');
// Create the first line
$p1 = new LinePlot($datay1);
$graph->Add($p1);
$p1->SetColor("#9495ED");
$p1->SetLegend('READ');
// Create the second line
$p2 = new LinePlot($datay2);
$graph->Add($p2);
$p2->SetColor("#B25522");
$p2->SetLegend('SENT');
// Create the third line
$p3 = new LinePlot($datay3);
$graph->Add($p3);
$p3->SetColor("#FF1493");
$p3->SetLegend('T001');
// Create the fourth line
$p4 = new LinePlot($datay4);
$graph->Add($p4);
$p4->SetColor("#FF1441");
$p4->SetLegend('T002');
$graph->legend->SetFrameWeight(3);
// Output line
$graph->Stroke();
?>
un ejemplo sencillo y completo.
ahora veremos un ejemplo mas practico y de un nivel un poco mas elevado
la idea sera:
- Obtener la cantidad de ocurrencias para los registros de SENT,READ,TO01 yTO02 que esten entre los rangos 60000 y 220000 dentro de la base de datos, cabe destacar que 60000 y 220000 corresponde horas, es decir 60000 es igual a 6:00 como 220000 es a 22:00 Hrs (para mayor comodidad del lector).
cod3:
require('jpgraph/jpgraph.php');
require('jpgraph/jpgraph_line.php');
require('jpgraph/jpgraph_line.php');
$matriz[1]="\"READ\"";
$matriz[2]="\"SENT\"";
$matriz[3]="\"TO01\"";
$matriz[4]="\"TO02\"";
$table=$_SESSION['table'];
$conexion=mysql_connect($server, $user, $pass) or
die("Error en conexion con motor".mysql_error());
mysql_select_db($bbdd,$conexion) or
die("Fallo al selecionar la BBDD");
//array para read sent TO01 y TO02
$i=0;
foreach($matriz as $key => $value){
$x=1;
for($i=60000;$i<=220000;$i=$i+10000){
$aux=$i+10000;
$x++;
$consulta=mysql_query("Select count(*) as total from ".$table." where hora >".$i." and hora < ".$aux." and status =".$value,$conexion); // sumatoria de las ocurrencias
if ($file = mysql_fetch_array($consulta)){
// asignando resultados
if($key==1)
$datay1[$x] = $file["total"];
if($key==2)
$datay2[$x] = $file["total"];
if($key==3)
$datay3[$x] = $file["total"];
if($key==4)
$datay4[$x] = $file["total"];
}
}
}
...setup graph ...
$matriz[2]="\"SENT\"";
$matriz[3]="\"TO01\"";
$matriz[4]="\"TO02\"";
$table=$_SESSION['table'];
$conexion=mysql_connect($server, $user, $pass) or
die("Error en conexion con motor".mysql_error());
mysql_select_db($bbdd,$conexion) or
die("Fallo al selecionar la BBDD");
//array para read sent TO01 y TO02
$i=0;
foreach($matriz as $key => $value){
$x=1;
for($i=60000;$i<=220000;$i=$i+10000){
$aux=$i+10000;
$x++;
$consulta=mysql_query("Select count(*) as total from ".$table." where hora >".$i." and hora < ".$aux." and status =".$value,$conexion); // sumatoria de las ocurrencias
if ($file = mysql_fetch_array($consulta)){
// asignando resultados
if($key==1)
$datay1[$x] = $file["total"];
if($key==2)
$datay2[$x] = $file["total"];
if($key==3)
$datay3[$x] = $file["total"];
if($key==4)
$datay4[$x] = $file["total"];
}
}
}
...setup graph ...
