Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/11/2010, 06:39
oleoleueiuei
 
Fecha de Ingreso: noviembre-2010
Mensajes: 1
Antigüedad: 13 años, 5 meses
Puntos: 0
Pregunta MySQL y Jpgraph

Hola a todos, he ingresado en este foro para ver si alguien me puede echar una mano.

La cuestión es que tengo una base de datos mysql con una tabla en la cual la primera columna es timestamp y la segunda es una variable asociada a cada fecha. Mediante un formulario se eligen el dia y hora inicial y final.

Lo que quiero es dibujarlo gráficamente a modo de evolución temporal de la variable con jpgraph de manera que en el "eje x" aparezca la fecha y hora de la 1ª columna y el el "eje y" aparezca el valor de la variable de la segunda columna. No me acepta la opcion datlin a pesar de haber hecho pruebas con el fichero jpgraph_date.php y las opciones linlin, intlin, textlin, etc no me dan el resultado esperado. Os pego un trozo de mi código php y a ver si alguien me puede ayudar. Gracias

<?php
$link = mysql_connect('localhost', 'root', '*******');
mysql_select_db("****", $link);
...
$result = mysql_query("SELECT fecha,variable FROM tabla WHERE fecha>='$inicio' and fecha<='$final'", $link);
$row = mysql_fetch_row($result);

include("./jpgraph/jpgraph.php");
include("./jpgraph/jpgraph_line.php");

$datay=array();
$datax=array();

while ($row_graph = mysql_fetch_array($result)) {
$datay[] = $row_graph['variable'];
$datax[] = $row_graph['fecha'];
}

$graph = new Graph(800, 600, "auto");
$graph->SetScale("intlin");
$graph->xaxis->SetLabelAngle(90);
$graph->xaxis->SetLabelFormatCallback('formatDate');
function formatDate($datax) {
$datax = date('Y-m-d H:i',$datax);
}
$t=array_walk($datax,'formatDate');
$graph->xaxis->SetTickLabels($t);

$graph->img->SetMargin(80,30,120,150);
$graph->title->Set("$inicio a $final");
$graph->yaxis->title->Set("Temp. virtual (C)");
$graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
$graph->title->SetFont(FF_FONT1, FS_BOLD);
$graph->ygrid->Show(true);
$graph->xgrid->Show(true);

$lineplot = new LinePlot($datay);
$lineplot->SetColor("red");
$lineplot->SetWeight(2);
$graph->Add($lineplot);
$graph->Stroke();
}
}
?>