Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/07/2013, 15:02
Montes28
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
problema para graficar serie de tiempo con jpgraph

hola amigos espero me puedan ayudar,

la situación es la siguiente: requiero graficar aproximadamente 1000 registros los cuales los obtengo mediante una consulta a la base de datos (postgresql).

Esta es la estructura de la tabla donde se guardan los registros
id serial
fecha date
hora time without time zone
temperatura real

ejemplo de un registro

id fecha hora temperatura
2 2013-07-23 17:23:04 -0.25

los registro tienen un minuto de diferencia.

el problema que tengo es como logro que en el eje de x aparezcan los valores de las horas y no los minutos.

esta es mi consulta
Código SQL:
Ver original
  1. SELECT * FROM anemometro WHERE fecha > now()-'24 hour'::INTERVAL;

hasta el momento este es mi código el cual es el ejemplo de jpgraph , como lo integro

Código PHP:
Ver original
  1. <?php // content="text/plain; charset=utf-8"
  2. require_once ('jpgraph/jpgraph.php');
  3. require_once ('jpgraph/jpgraph_line.php');
  4. require_once ('jpgraph/jpgraph_date.php');
  5.  
  6. // Create a data set in range (50,70) and X-positions
  7. DEFINE('NDATAPOINTS',360);
  8. DEFINE('SAMPLERATE',240);
  9. $start = time();
  10. $end = $start+NDATAPOINTS*SAMPLERATE;
  11. $data = array();
  12. $xdata = array();
  13. for( $i=0; $i < NDATAPOINTS; ++$i ) {
  14.     $data[$i] = rand(50,70);
  15.     $xdata[$i] = $start + $i * SAMPLERATE;
  16. }
  17.  
  18.  
  19. // Create the new graph
  20. $graph = new Graph(540,600);
  21.  
  22. // Slightly larger than normal margins at the bottom to have room for
  23. // the x-axis labels
  24. $graph->SetMargin(40,40,30,130);
  25.  
  26. // Fix the Y-scale to go between [0,100] and use date for the x-axis
  27. $graph->SetScale('datlin',0,100);
  28. $graph->title->Set("Example on Date scale");
  29.  
  30. // Set the angle for the labels to 90 degrees
  31. $graph->xaxis->SetLabelAngle(90);
  32.  
  33. $line = new LinePlot($data,$xdata);
  34. $line->SetLegend('Year 2005');
  35. $line->SetFillColor('[email protected]');
  36. $graph->Add($line);
  37. $graph->Stroke();
  38. ?>