Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/08/2012, 22:30
Montes28
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
Problema con jpgraph y postgresql

hola amigos espero me puedan ayudar, estoy empezando a trabajar con jpgraph y necesito plotear una consulta a una base datos.

tome como referencia el ejemplo que se encuentra en la documentacion.

en el dataset01.inc.php
los datos estan de la siguiente manera

$ydata = array(
0 => 1.0885908919277, 1 =>
0.99034385297982, 2 => 0.97005467188578, 3 =>..............

$xdata = array(

0 => 444348000, 1 => 446853600, 2 =>
449532000, 3 => 452124000, 4 =>..................................

Código PHP:
Ver original
  1. include('inc/jpgraph.php');
  2. include('inc/jpgraph_line.php');
  3. include('inc/jpgraph_date.php');
  4. include('inc/jpgraph_utils.inc.php');
  5.  
  6. // Get a dataset stored in $xdata and $ydata
  7. include('inc/dataset01.inc.php');
  8.  
  9.  
  10. $dateUtils = new DateScaleUtils();
  11.  
  12. // Setup a basic graph
  13. $width=700; $height=400;
  14. $graph = new Graph($width, $height);
  15. $graph->SetScale('datlin');
  16. $graph->SetMargin(60,20,40,60);
  17.  
  18. // Setup the titles
  19. $graph->title->SetFont(FF_ARIAL,FS_BOLD,12);
  20. $graph->title->Set('Development since 1984');
  21. $graph->subtitle->SetFont(FF_ARIAL,FS_ITALIC,10);
  22. $graph->subtitle->Set('(Example using the builtin date scale)');
  23.  
  24. // Setup the labels to be correctly format on the X-axis
  25. $graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
  26. $graph->xaxis->SetLabelAngle(30);
  27.  
  28. $lp1 = new LinePlot($ydata,$xdata);
  29. $lp1->SetWeight(0);
  30. $lp1->SetFillColor('[email protected]');
  31. $graph->Add($lp1);
  32.  
  33. // And then add line. We use two plots in order to get a
  34. // more distinct border on the graph
  35. $lp2 = new LinePlot($ydata,$xdata);
  36. $lp2->SetColor('orange');
  37. $graph->Add($lp2);
  38.  
  39. // And send back to the client
  40. $graph->Stroke();


los datos devuelos por la consulta son los siguientes

campo 1 campo 2
timestamp with time zone real
"2012-06-27 00:00:46-05" 2
"2012-06-27 00:07:34-05" 5
"2012-06-27 00:13:03-05" 20
"2012-06-27 00:15:19-05" 15
"2012-06-27 00:22:19-05" 10


y mi codigo es el siguiente

Código PHP:
Ver original
  1. include('inc/jpgraph.php');
  2. include('inc/jpgraph_line.php');
  3. include('inc/jpgraph_date.php');
  4. include('inc/jpgraph_utils.inc.php');
  5.  
  6. $dateUtils = new DateScaleUtils();
  7.  
  8.  
  9. $width=700; $height=400;
  10. $graph = new Graph($width, $height);
  11. $graph->SetScale('datlin');
  12. $graph->SetMargin(60,20,40,60);
  13.  
  14. $graph->title->SetFont(FF_ARIAL,FS_BOLD,12);
  15. $graph->title->Set('Development since 1984');
  16. $graph->subtitle->SetFont(FF_ARIAL,FS_ITALIC,10);
  17. $graph->subtitle->Set('(Example using the builtin date scale)');
  18.  
  19.  
  20. $graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
  21. $graph->xaxis->SetLabelAngle(30);
  22.  
  23.                 $servidor = 'localhost';
  24.         $bd = 'tremor';
  25.         $usuario = 'postgres';
  26.         $contrasenia = '*****';
  27.         $tabla = 'tremor';
  28.        
  29.  
  30.         global $servidor, $bd, $usuario, $contrasenia;
  31.         $db = new PDO('pgsql:host=' . $servidor . ';dbname=' . $bd, $usuario, $contrasenia);
  32.  
  33.         $consulta = $db->prepare("SELECT campo5, campo1 FROM tremor");
  34.         $consulta->execute();
  35.  
  36.         while($fila = $consulta->fetch(PDO::FETCH_ASSOC))
  37.         {
  38.         $xdata[] = $fila['campo5'];
  39.         $ydata[] = $fila['campo1'];
  40.  
  41.         }
  42.  
  43.  
  44. $lp1 = new LinePlot($ydata,$xdata);
  45. $lp1->SetWeight(0);
  46. $lp1->SetFillColor('[email protected]');
  47. $graph->Add($lp1);
  48.  
  49.  
  50. $lp2 = new LinePlot($ydata,$xdata);
  51. $lp2->SetColor('orange');
  52. $graph->Add($lp2);
  53.  
  54.  
  55. $graph->Stroke();


el error que obtengo es el siguiente:
cannot use auto scaling since it is impossible to determine a valid min/max value of the y-axis (only null values)