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 originalinclude('inc/jpgraph.php');
include('inc/jpgraph_line.php');
include('inc/jpgraph_date.php');
include('inc/jpgraph_utils.inc.php');
// Get a dataset stored in $xdata and $ydata
include('inc/dataset01.inc.php');
$dateUtils = new DateScaleUtils();
// Setup a basic graph
$width=700; $height=400;
$graph = new Graph($width, $height);
$graph->SetScale('datlin');
$graph->SetMargin(60,20,40,60);
// Setup the titles
$graph->title->SetFont(FF_ARIAL,FS_BOLD,12);
$graph->title->Set('Development since 1984');
$graph->subtitle->SetFont(FF_ARIAL,FS_ITALIC,10);
$graph->subtitle->Set('(Example using the builtin date scale)');
// Setup the labels to be correctly format on the X-axis
$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
$graph->xaxis->SetLabelAngle(30);
$lp1 = new LinePlot($ydata,$xdata);
$lp1->SetWeight(0);
$graph->Add($lp1);
// And then add line. We use two plots in order to get a
// more distinct border on the graph
$lp2 = new LinePlot($ydata,$xdata);
$lp2->SetColor('orange');
$graph->Add($lp2);
// And send back to the client
$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 originalinclude('inc/jpgraph.php');
include('inc/jpgraph_line.php');
include('inc/jpgraph_date.php');
include('inc/jpgraph_utils.inc.php');
$dateUtils = new DateScaleUtils();
$width=700; $height=400;
$graph = new Graph($width, $height);
$graph->SetScale('datlin');
$graph->SetMargin(60,20,40,60);
$graph->title->SetFont(FF_ARIAL,FS_BOLD,12);
$graph->title->Set('Development since 1984');
$graph->subtitle->SetFont(FF_ARIAL,FS_ITALIC,10);
$graph->subtitle->Set('(Example using the builtin date scale)');
$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
$graph->xaxis->SetLabelAngle(30);
$servidor = 'localhost';
$bd = 'tremor';
$usuario = 'postgres';
$contrasenia = '*****';
$tabla = 'tremor';
global $servidor, $bd, $usuario, $contrasenia;
$db = new PDO('pgsql:host=' . $servidor . ';dbname=' . $bd, $usuario, $contrasenia);
$consulta = $db->prepare("SELECT campo5, campo1 FROM tremor");
$consulta->execute();
while($fila = $consulta->fetch(PDO::FETCH_ASSOC))
{
$xdata[] = $fila['campo5'];
$ydata[] = $fila['campo1'];
}
$lp1 = new LinePlot($ydata,$xdata);
$lp1->SetWeight(0);
$graph->Add($lp1);
$lp2 = new LinePlot($ydata,$xdata);
$lp2->SetColor('orange');
$graph->Add($lp2);
$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)