Ver Mensaje Individual
  #2 (permalink)  
Antiguo 17/02/2008, 14:41
Avatar de Bizo21
Bizo21
 
Fecha de Ingreso: abril-2004
Ubicación: Valdivia
Mensajes: 93
Antigüedad: 20 años
Puntos: 1
Re: crear grafico con mysql y php

Hola a todos ya encontre como sacar los datos y hacer el grafico aca les dejo lo que hice:

include("db.php");
$total_si="";
$total_no="";
$total_na="";

$sql="select * from eval_obs where c_evaluacion='123'";
$query=mysql_query($sql) or die ("ERRO al mostrar el select:" .mysql_error());

$datos=mysql_fetch_array($query);

if($datos['ie1']=="SI") $total_si++;
if($datos['ie1']=="NO") $total_no++;
if($datos['ie1']=="N/A")$total_na++;

if($datos['ie2']=="SI") $total_si++;
if($datos['ie2']=="NO") $total_no++;
if($datos['ie2']=="N/A")$total_na++;

if($datos['ie3']=="SI") $total_si++;
if($datos['ie3']=="NO") $total_no++;
if($datos['ie3']=="N/A")$total_na++;

if($datos['ie4']=="SI") $total_si++;
if($datos['ie4']=="NO") $total_no++;
if($datos['ie4']=="N/A")$total_na++;

if($datos['ie5']=="SI") $total_si++;
if($datos['ie5']=="NO") $total_no++;
if($datos['ie5']=="N/A")$total_na++;

/* claro aca hay que segir colocando los campos si tienen mas */

/*asi te mostrara cuanto de cada uno hay en la base de datos*/
echo"$total_si ";
echo"$total_no ";
echo"$total_na ";
?>

si lo quieres pasar a un grafico con jpgraph hacen esto :

<?php

include("db.php");
include ("../jpgraph/src/jpgraph.php");
include ("../jpgraph/src/jpgraph_bar.php");

$total_si="";
$total_no="";
$total_na="";

$sql="select * from eval_obs where c_evaluacion='123'";
$query=mysql_query($sql) or die ("ERRO al mostrar el select:" .mysql_error());

$datos=mysql_fetch_array($query);

if($datos['ie1']=="SI") $total_si++;
if($datos['ie1']=="NO") $total_no++;
if($datos['ie1']=="N/A")$total_na++;

if($datos['ie2']=="SI") $total_si++;
if($datos['ie2']=="NO") $total_no++;
if($datos['ie2']=="N/A")$total_na++;

if($datos['ie3']=="SI") $total_si++;
if($datos['ie3']=="NO") $total_no++;
if($datos['ie3']=="N/A")$total_na++;

if($datos['ie4']=="SI") $total_si++;
if($datos['ie4']=="NO") $total_no++;
if($datos['ie4']=="N/A")$total_na++;

/* aca colocan su variable que trae los datos de su base de datos */

$datay=array($total_si,$total_no,$total_na);

// Create the graph. These two calls are always required
$graph = new Graph(300,200,"auto");
$graph->SetScale("textlin");
$graph->yaxis->scale->SetGrace(20);

// Add a drop shadow
$graph->SetShadow();

// Adjust the margin a bit to make more room for titles
$graph->img->SetMargin(40,30,20,40);

// Create a bar pot
$bplot = new BarPlot($datay);

// Adjust fill color
$bplot->SetFillColor('orange');
$bplot->SetShadow();
$bplot->value->Show();
$bplot->value->SetFont(FF_ARIAL,FS_BOLD,10);
$bplot->value->SetAngle(45);
$bplot->value->SetFormat('%0.1f');
$graph->Add($bplot);

// Setup the titles
$graph->title->Set("Grafico de Evaluacion de Observacion");
$graph->xaxis->title->Set("calidad");
$graph->yaxis->title->Set("cantidad");

$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);

// Display the graph
$graph->Stroke();
?>
y listo funciona claro que ahi cada uno le da el su toco personalizado ya que es solo un ejemplo y funciona.


de antemano gracias