Foros del Web » Programando para Internet » PHP »

Generar gráficos con PHP desde BD

Estas en el tema de Generar gráficos con PHP desde BD en el foro de PHP en Foros del Web. Que tal estoy tratando de generar reportes gráficos con PHP extrayendo los datos de una base de datos, para esto estoy utilizando la librería JPGRAPH. ...
  #1 (permalink)  
Antiguo 14/03/2013, 15:58
 
Fecha de Ingreso: octubre-2012
Mensajes: 7
Antigüedad: 11 años, 6 meses
Puntos: 0
Mensaje Generar gráficos con PHP desde BD

Que tal estoy tratando de generar reportes gráficos con PHP extrayendo los datos de una base de datos, para esto estoy utilizando la librería JPGRAPH. El problema que me esta surgiendo es que al correr el html este aparece en blanco.
Aquí dejo el código de mi conexion y donde genero el gráfico.

Este se llama "consulta2.php"
<?
$link = mysql_connect('localhost', 'user', 'password');
@mysql_database("indicadores",$link);
if (!$link) {
die('Error de Conexión' . mysql_error());
}
echo 'Conexión Correcta';
?>

En este código lo mando llamar para extraer los datos y generar el gráfico.

<?php
include ("consulta2.php");
include_once ("jpgraph.php");
include_once ("jpgraph_bar.php");

$query = mysql_query("SELECT nombre,producido FROM aa1");

while($row = mysql_fetch_array($query))
{
$data[] = $row[0];
$can[] = $row[1];
}

// Create the graph.
// One minute timeout for the cached image
// INLINE_NO means don't stream it back to the browser.
$graph = new Graph(310,250,'auto');
$graph->SetScale("textlin");
$graph->img->SetMargin(60,30,20,40);
$graph->yaxis->SetTitleMargin(45);
$graph->yaxis->scale->SetGrace(30);
$graph->SetShadow();

// Turn the tickmarks
$graph->xaxis->SetTickSide(SIDE_DOWN);
$graph->yaxis->SetTickSide(SIDE_LEFT);

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

// Create targets for the image maps. One for each column
$targ=array("bar_clsmex1.php#1","bar_clsmex1.php#2 ","bar_clsmex1.php#3","bar_clsmex1.php#4","bar_cls mex1.php#5","bar_clsmex1.php#6");
$alts=array("val=%d","val=%d","val=%d","val=%d","v al=%d","val=%d");
$bplot->SetCSIMTargets($targ,$alts);
$bplot->SetFillColor("orange");

// Use a shadow on the bar graphs (just use the default settings)
$bplot->SetShadow();
$bplot->value->SetFormat(" $ %2.1f",70);
$bplot->value->SetFont(FF_ARIAL,FS_NORMAL,9);
$bplot->value->SetColor("blue");
$bplot->value->Show();

$graph->Add($bplot);

$graph->title->Set("Línea AA1, 2, 9, E3");
$graph->xaxis->title->Set("Supervisor");
$graph->yaxis->title->Set("Objetivo");

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

// Send back the HTML page which will call this script again
// to retrieve the image.
$graph->StrokeCSIM();
?>

Espero me puedan ayudar, porque me esta rompiendo la cabeza este proyecto. De antemano, gracias y saludos!
  #2 (permalink)  
Antiguo 14/03/2013, 16:11
Colaborador
 
Fecha de Ingreso: mayo-2008
Ubicación: $MX['VZ']['Xalapa']
Mensajes: 3.005
Antigüedad: 15 años, 11 meses
Puntos: 528
Respuesta: Generar gráficos con PHP desde BD

Primero asegúrate de que tu script js y html funcionan con datos fijos, luego verifica que estos valores sean correctamente sustituidos por los datos de la bd por php.

Finalmente, usa la opción highlight del foro para que tu código sea más fácil de leer.
  #3 (permalink)  
Antiguo 14/03/2013, 16:24
 
Fecha de Ingreso: octubre-2012
Mensajes: 7
Antigüedad: 11 años, 6 meses
Puntos: 0
Respuesta: Generar gráficos con PHP desde BD

Con datos fijos funciona correctamente, el problema es que no me muestra nada.
lo pongo nuevamente:

Así hago conexión a la base de datos.
Código PHP:
Ver original
  1. <?
  2.     $link = mysql_connect('localhost', 'user', 'password');
  3.     @mysql_database("indicadores",$link);
  4.     if (!$link) {
  5.         die('Error de Conexión' . mysql_error());
  6.                 }
  7.     echo 'Conexión Correcta';
  8. ?>

Ahora esa conexión la llamo al archivo php en el cual quiero generar la gráfica:
Y es en la cual en la que no sé si estoy haciendolo bien!
Código PHP:
Ver original
  1. <?php
  2. include      ("consulta2.php");//Este php es donde estoy llamando la conexión
  3. include_once ("jpgraph.php");
  4. include_once ("jpgraph_bar.php");
  5.  
  6. $query = mysql_query("SELECT nombre,producido FROM aa1");
  7.  
  8.     while($row = mysql_fetch_array($query))
  9.     {
  10.      $data[] = $row[0];
  11.      $can[] = $row[1];
  12.     }
  13.  
  14. // Create the graph.
  15. // One minute timeout for the cached image
  16. // INLINE_NO means don't stream it back to the browser.
  17. $graph = new Graph(310,250,'auto');
  18. $graph->SetScale("textlin");
  19. $graph->img->SetMargin(60,30,20,40);
  20. $graph->yaxis->SetTitleMargin(45);
  21. $graph->yaxis->scale->SetGrace(30);
  22. $graph->SetShadow();
  23.  
  24. // Turn the tickmarks
  25. $graph->xaxis->SetTickSide(SIDE_DOWN);
  26. $graph->yaxis->SetTickSide(SIDE_LEFT);
  27.  
  28. // Create a bar pot
  29. $bplot = new BarPlot($can);
  30.  
  31. // Create targets for the image maps. One for each column
  32. $targ=array("bar_clsmex1.php#1","bar_clsmex1.php#2","bar_clsmex1.php#3","bar_clsmex1.php#4","bar_clsmex1.php#5","bar_clsmex1.php#6");
  33. $alts=array("val=%d","val=%d","val=%d","val=%d","val=%d","val=%d");
  34. $bplot->SetCSIMTargets($targ,$alts);
  35. $bplot->SetFillColor("orange");
  36.  
  37. // Use a shadow on the bar graphs (just use the default settings)
  38. $bplot->SetShadow();
  39. $bplot->value->SetFormat(" $ %2.1f",70);
  40. $bplot->value->SetFont(FF_ARIAL,FS_NORMAL,9);
  41. $bplot->value->SetColor("blue");
  42. $bplot->value->Show();
  43.  
  44. $graph->Add($bplot);
  45.  
  46. $graph->title->Set("Línea AA1, 2, 9, E3");
  47. $graph->xaxis->title->Set("Supervisor");
  48. $graph->yaxis->title->Set("Objetivo");
  49.  
  50. $graph->title->SetFont(FF_FONT1,FS_BOLD);
  51. $graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
  52. $graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
  53.  
  54. // Send back the HTML page which will call this script again
  55. // to retrieve the image.
  56. $graph->StrokeCSIM();
  57. ?>
Espero puedas ayudarme!

Etiquetas: bd, html, mysql, select
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:04.