Foros del Web » Programando para Internet » PHP »

Jpgraph y paso de variables en imagen

Estas en el tema de Jpgraph y paso de variables en imagen en el foro de PHP en Foros del Web. Estoy trabajando con jpgraph y según la documentación dice que se pueden pasar valores a través de la etiqueta Código: <img> pero no se si ...
  #1 (permalink)  
Antiguo 02/03/2009, 15:44
 
Fecha de Ingreso: octubre-2008
Mensajes: 109
Antigüedad: 15 años, 6 meses
Puntos: 0
Pregunta Jpgraph y paso de variables en imagen

Estoy trabajando con jpgraph y según la documentación dice que se pueden pasar valores a través de la etiqueta
Código:
<img>
pero no se si se puede trabajar igual que una url para obtener datos mediante $_GET/$_POST.

Aquí les dejo lo que dice en la documentación:

Cita:
4.4 The basic principle of JpGraph and the creation of images

The common pattern for creating graphs is

1. Create a script that constructs the image, type, colors size and so on.
2. A wrapper script which contains one or more <IMG> tags to position the graphs on the proper HTML page.

Of course it is of perfectly possible to call the image script directly in the browser to just display the generated image in the browser.

You should remember that it is also possible to pass arguments to the image script via the normal HTTP GET/POST arguments. For example
<img src ="showgraph.php?a=1&b=2" >

This could for example be used to control the appearance of the image or perhaps send data to the image which will be displayed. Note that this is probably not the best way to send large amount of data to plot. Instead the only practical way, for large data sizes, is to get all the data in the image script, perhaps from a DB. Another alternative for large amount of data to be sent to the image script is by creating a POST request to the image script.
Alguien ha probado a hacer algo así???
  #2 (permalink)  
Antiguo 02/03/2009, 15:48
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Jpgraph y paso de variables en imagen

de hecho, si... muchos lo hacen!

Código HTML:
<img src="jgraph.php?x=99&y=33&w=128&h=24"/> 
etc, etc... suerte!


--
¿cual es el problema??

lo digo, por que lo que se usa en src/href son eso... URLs
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 02/03/2009, 17:09
 
Fecha de Ingreso: octubre-2008
Mensajes: 109
Antigüedad: 15 años, 6 meses
Puntos: 0
Respuesta: Jpgraph y paso de variables en imagen

Si pero como los obtengo?
Si yo paso estos valores :<img src="jgraph.php?x=99&y=33&w=128&h=24"/>
sería $_GET['x'] pero eso no va dentro del url así qque como obtienes los datos en el source de una imagen.
????
  #4 (permalink)  
Antiguo 02/03/2009, 17:13
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Respuesta: Jpgraph y paso de variables en imagen

Tal como indicas dentro de jgraph.php recoges $_GET['x'], $_GET['y'], $_GET['w'] y $_GET['h'].

Saludos
  #5 (permalink)  
Antiguo 02/03/2009, 18:08
 
Fecha de Ingreso: octubre-2008
Mensajes: 109
Antigüedad: 15 años, 6 meses
Puntos: 0
Respuesta: Jpgraph y paso de variables en imagen

Sigue sin funcionar...
TEngo esto:

Esta página llama a 88888 y ahí es donde llamo a la imagen...
Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>

<form action="88888.php">
<select name="estado" >
<option value="01">aguascalientes</option>
</select>
<input type="submit" />
</form>
</body>

</html>
ESte es el archivo 88888
Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<? if(isset($_GET['estado'])) 
$est= $_GET['estado'];
?>

<div align="center">
<img src="bar2scalesex1.php?estado=<? echo $est; ?>" />
</div>
</body>
</html>
Y este archivo barscalesex1.php, es el que me genera la grafica de acuerdo al estado enviado pero no recibo tal valor

Código:
<?php
if(isset($_GET['estado'])) 
$est= $_GET['estado'];
echo "estado:".$est;
include ("jpgraph/jpgraph.php");
include ("jpgraph/jpgraph_bar.php");

$dbhost="t";  // host del MySQL (generalmente localhost)
$dbusuario="t"; // aqui debes ingresar el nombre de usuario
                      // para acceder a la base
$dbpassword="t"; // password de acceso para el usuario de la
                      // linea anterior
$db="alianza";        // Seleccionamos la base con la cual trabajar
$conexion = mysql_connect($dbhost, $dbusuario, $dbpassword);
mysql_select_db($db, $conexion);



$consulta="select m from inm_domicilio where m=1";
$result2=mysql_query($consulta, $conexion);
$row2 = mysql_fetch_row($result2);
$tpm = $row2[0];
mysql_free_result($result2);

$consulta2="select c from inm_domicilio where c=1";
$result2=mysql_query($consulta2, $conexion);
$row2 = mysql_fetch_row($result2);
$tpc = $row2[0];
mysql_free_result($result2);	

$consulta3="select i from inm_domicilio where i=1";
$result2=mysql_query($consulta3, $conexion);
$row2 = mysql_fetch_row($result2);
$tpi = $row2[0];
mysql_free_result($result2);


$datay=array(($tpm/1000000),($tpc/1000000),($tpi/1000000));
$datay2=array(700,930,1000);
$datazero=array(0,0,0);

// Create the graph. 

$graph = new Graph(600,400);
$graph->title->Set('Presupuesto Por Programa (mdp)');

// Setup Y and Y2 scales with some "grace"	
$graph->SetScale("textlin");
$graph->SetY2Scale("lin");
$graph->yaxis->scale->SetGrace(50);
$graph->y2axis->scale->SetGrace(50);
$graph->yaxis->title->Set("hola");

//$graph->ygrid->Show(true,true);
$graph->ygrid->SetColor('gray','[email protected]');

// Setup graph colors
$graph->SetMarginColor('white');
$graph->y2axis->SetColor('darkred');


// Create the "dummy" 0 bplot
$bplotzero = new BarPlot($datazero);

// Create the "Y" axis group
$ybplot1 = new BarPlot($datay);
$ybplot1->value->Show();
$ybplot = new GroupBarPlot(array($ybplot1,$bplotzero));

// Create the "Y2" axis group
$ybplot2 = new BarPlot($datay2);
$ybplot2->value->Show();
$ybplot2->value->SetColor('darkred');
$ybplot2->SetFillColor('darkred');
$y2bplot = new GroupBarPlot(array($bplotzero,$ybplot2));

// Add the grouped bar plots to the graph
$graph->Add($ybplot);
$graph->AddY2($y2bplot);

// .. and finally stroke the image back to browser
$graph->Stroke();
?>
Como sería?
Ya busque si se puede obtener la variable desde una imagen y nada.... :(
  #6 (permalink)  
Antiguo 02/03/2009, 18:25
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Jpgraph y paso de variables en imagen

Asegurate de que $est tenga un valor inicial y tambien validalo con las opciones que tengas disponibles en tu script.

Código php:
Ver original
  1. $est = 'valor inicial';
  2. if(isset($_GET['estado']))
  3.      $est= $_GET['estado'];
__________________
- León, Guanajuato
- GV-Foto
  #7 (permalink)  
Antiguo 02/03/2009, 21:21
 
Fecha de Ingreso: octubre-2008
Mensajes: 109
Antigüedad: 15 años, 6 meses
Puntos: 0
Respuesta: Jpgraph y paso de variables en imagen

No funciona , no tendrás un ejemplo o un link???
  #8 (permalink)  
Antiguo 02/03/2009, 22:06
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Respuesta: Jpgraph y paso de variables en imagen

Revisa que la imagen tenga los parametros correctos a la hora de imprimir la imagen realiza un botón derecho y ver código fuente con eso ves el HTML y puedes ver si esta pasando o no una variable.

Saludos
  #9 (permalink)  
Antiguo 03/03/2009, 11:10
 
Fecha de Ingreso: octubre-2008
Mensajes: 109
Antigüedad: 15 años, 6 meses
Puntos: 0
Respuesta: Jpgraph y paso de variables en imagen

Cita:
Iniciado por GatorV Ver Mensaje
Revisa que la imagen tenga los parametros correctos a la hora de imprimir la imagen realiza un botón derecho y ver código fuente con eso ves el HTML y puedes ver si esta pasando o no una variable.

Saludos
Tal vez no me haya dado bien a entender:

En el archivo principal donde esta el form llamo al archivo 88888 que contiene la imagen que se genera en jpgraph.
Así:
Código PHP:
src="bar2scalesex1.php?estado=<? echo $est?>
y de esa forma es como quiero que se genera la gráfica para la variable que le estoy pasando, en este caso "estado" pero no me genera nada....
El archvio bar2scalesex1.php es el que genera la grafica y es por eso que le paso la variable estado.
  #10 (permalink)  
Antiguo 03/03/2009, 11:13
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Respuesta: Jpgraph y paso de variables en imagen

Pues el problema puede ser debido a que haces un: echo "estado:".$est; al principio de tu script, no se si sepas pero no puedes enviar nada de contenido de texto cuando vas a imprimir una imagen.

Para hacer "testing" en este caso lo más recomendable es que abras directo la imagen por URL en tu navegador y veas lo que te imprime.

Saludos
  #11 (permalink)  
Antiguo 03/03/2009, 11:17
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Jpgraph y paso de variables en imagen

claro... demás, prueba abrir la URL de la imagen manualmente en el navegador

o darle click derecho > "Ver Imagen" ...

¿que arroja??
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
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

SíEste tema le ha gustado a 1 personas




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