Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] problema con graficas

Estas en el tema de problema con graficas en el foro de PHP en Foros del Web. Hola amigos, sigo con mi problema de graficas con jpgraph, ya por fin la logre dibujar y todo, ahora lo q intento es q cuando ...
  #1 (permalink)  
Antiguo 25/11/2009, 12:26
Avatar de dcreate  
Fecha de Ingreso: octubre-2009
Ubicación: Veracruz
Mensajes: 536
Antigüedad: 14 años, 6 meses
Puntos: 22
problema con graficas

Hola amigos, sigo con mi problema de graficas con jpgraph, ya por fin la logre dibujar y todo, ahora lo q intento es q cuando pase el puntero por arriba de cada objeto muetre un valor, bueno aki esta una forma:

index.php

Código PHP:
<!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=iso-8859-1" />
<
title>Documento sin t&iacute;tulo</title>
</
head>

<
body>
<
form id="form1" name="form1" method="post" action="grafica.php">
  <
label>
  
VALOR 1:
  <
input name="valor1" type="text" id="valor1" />
  </
label>
  <
p>
    <
label>VALOR 2:
    <
input name="valor2" type="text" id="valor2" />
    </
label>
  </
p>
  <
p>VALOR 3
    <
label>
    <
input name="valor3" type="text" id="valor3" />
    </
label>
</
p>
  <
p>
    <
label>
    <
input type="submit" name="Submit" value="Enviar" />
    </
label>
  </
p>
</
form>
</
body>
</
html
grafica.php

Código PHP:
<?php 
$valor1
=$_POST['valor1'];
$valor2=$_POST['valor2'];
$valor3=$_POST['valor3'];
require_once (
"jpgraph/jpgraph.php"); 
require_once (
"jpgraph/jpgraph_line.php"); 
require_once (
"jpgraph/jpgraph_bar.php"); 

// content="text/plain; charset=utf-8" 

//$datay = array($valor1,$valor2,$valor3); 
$datay = array(12,56,34); 

$targ = array($valor1,$valor2,$valor3);
$alt = array($valor1,$valor2,$valor3); 

// Create the graph. 
$graph = new Graph(980,680);
$graph->SetMarginColor('white');
$graph->SetScale("textlin");
$graph->SetShadow();
$graph->SetFrame(true);
$graph->img->SetMargin(80,30,80,40);
$graph->title->Set('GRAFICA');
$graph->ygrid->SetFill(true,'#[email protected]','#[email protected]');

// Create the linear plot 
$lineplot=new LinePlot($datay); 
$lineplot->SetCenter();
$lineplot->mark->SetType(MARK_FILLEDCIRCLE);
$lineplot->mark->SetWidth(5);
$lineplot->mark->SetColor('black');
$lineplot->mark->SetFillColor('red');
$lineplot->SetCSIMTargets($targ,$alt);

// Add the plots to the graph 
$graph->Add($lineplot);  

$graph->StrokeCSIM();

?>
bueno aki si me dibuja la grafica con el arreglo:

Código php:
Ver original
  1. $datay = array(12,56,34);

pero si lo cambio por esto

Código php:
Ver original
  1. $datay = array($valor1,$valor2,$valor3);

aparece error de q el array no contiene nada, alguien q me pueda ayudar, e estoy volviendo loco con esto
  #2 (permalink)  
Antiguo 25/11/2009, 13:00
Avatar de Fairy_Boy  
Fecha de Ingreso: octubre-2009
Ubicación: Kokiri Forest
Mensajes: 235
Antigüedad: 14 años, 6 meses
Puntos: 5
Respuesta: problema con graficas

Hola Dcreate!
Se que no es una solucion directa para tu codigo, pero estoy haciendo un sistema, el cual requiere graficos y hace tiempo encontre estos que son muy buenos y libres.
Ademas, buscando y buscando, encontre un tutorial muy facil en un blog.
Saludos!


PD: No tengo la intencion de hacerle Spam a nadie ^^
  #3 (permalink)  
Antiguo 25/11/2009, 13:20
Avatar de dcreate  
Fecha de Ingreso: octubre-2009
Ubicación: Veracruz
Mensajes: 536
Antigüedad: 14 años, 6 meses
Puntos: 22
Respuesta: problema con graficas

grax fairy_boy, estuve viendo un poco los enlaces, crea una grafica en swf, mi pregunta es si la grafica te la propiedad de pasar el puntero del mouse por encima y mostrarte el valor o cuando le des clic sobre algun objeto pueda abrir una pagina extraa
  #4 (permalink)  
Antiguo 25/11/2009, 13:29
Avatar de Fairy_Boy  
Fecha de Ingreso: octubre-2009
Ubicación: Kokiri Forest
Mensajes: 235
Antigüedad: 14 años, 6 meses
Puntos: 5
Respuesta: problema con graficas

si te fijas en el enlace que dice "estos", te envia a la pag principal de la libreria
ahi veas todos los tipos de graficos que se pueden hacer con dicha libreria y veras que si pasas el cursor por cada punto, lo mostrara en un globo.
pero lo de la pagina extra, no lo he visto aun, pero yo creo que se puede.
la verdad estoy implementando hace poco esta libreria.
  #5 (permalink)  
Antiguo 25/11/2009, 13:35
Avatar de gjx2  
Fecha de Ingreso: agosto-2008
Ubicación: R.D
Mensajes: 1.153
Antigüedad: 15 años, 8 meses
Puntos: 139
Respuesta: problema con graficas

Solucion Al primer problema de
dcreate



Código php:
Ver original
  1. require_once ("jpgraph/jpgraph.php");  
  2. require_once ("jpgraph/jpgraph_line.php");  
  3. require_once ("jpgraph/jpgraph_bar.php");  
  4.  
  5.  
  6. $valor1= $_POST['valor1'];
  7. $valor2= $_POST['valor2'];
  8. $valor3= $_POST['valor3'];
  9.  
  10.  
  11. $datay = array($valor1,$valor2,$valor3);
  12.  
  13. $graph = new Graph(980,680);
  14. $graph->SetMarginColor('white');
  15. $graph->SetScale("intlin");
  16. $graph->SetShadow();
  17. $graph->SetFrame(true);
  18. $graph->img->SetMargin(80,30,80,40);
  19. $graph->title->Set('GRAFICA');
  20. $graph->ygrid->SetFill(true,'#[email protected]','#[email protected]');
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27. // Create the linear plot  
  28. $lineplot=new LinePlot($datay);  
  29. $lineplot->SetCenter();
  30. $lineplot->mark->SetType(MARK_FILLEDCIRCLE);
  31. $lineplot->mark->SetWidth(5);
  32. $lineplot->mark->SetColor('black');
  33. $lineplot->mark->SetFillColor('red');
  34. //$lineplot->SetCSIMTargets($targ,$alt);
  35.  
  36. // Add the plots to the graph  
  37. $graph->Add($lineplot);  
  38.  
  39. $graph->Stroke();
  #6 (permalink)  
Antiguo 25/11/2009, 14:38
Avatar de dcreate  
Fecha de Ingreso: octubre-2009
Ubicación: Veracruz
Mensajes: 536
Antigüedad: 14 años, 6 meses
Puntos: 22
Respuesta: problema con graficas

hola gjx2, lamento decirt q eso ya lo podia hacer, lo q ahora necesito es poner el mapa para q cuando seleccione uno de las marcas me muestre el valor o cuando le de clic sobre el objeto me abra otra pagina, por eso tiene
Código php:
Ver original
  1. $lineplot->SetCSIMTargets($targ,$alt);
y
Código php:
Ver original
  1. $graph->StrokeCSIM();
para crear el mapa
  #7 (permalink)  
Antiguo 26/11/2009, 08:48
Avatar de dcreate  
Fecha de Ingreso: octubre-2009
Ubicación: Veracruz
Mensajes: 536
Antigüedad: 14 años, 6 meses
Puntos: 22
Respuesta: problema con graficas

hay alguien q me pueda ayudar, se le agradeceria demasiado
  #8 (permalink)  
Antiguo 11/05/2010, 19:40
Avatar de dcreate  
Fecha de Ingreso: octubre-2009
Ubicación: Veracruz
Mensajes: 536
Antigüedad: 14 años, 6 meses
Puntos: 22
Respuesta: problema con graficas

hola, por fin pude solucionar mi problema y por si acaso alguien se atora alguna vez en esto aki les dejo la solucion

este es index.php
Código PHP:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Documento sin título</title>
  6. </head>
  7.  
  8. <body>
  9. <form id="form1" name="form1" method="post" action="barcsim_popup.php">
  10. <?php
  11. for($i=0;$i<5;$i++)
  12. {
  13. $d=$i+1;
  14. echo 'CAMPO '. $d .': <input name="c'.$i.'" type="text" /><br><br>';
  15. }
  16. ?>  
  17. <input name="enviar" type="submit" value="ENVIAR"/>
  18. </form>
  19. <p>&nbsp;</p>
  20. </body>
  21. </html>

y este es barcsim_popup.php
Código PHP:
Ver original
  1. <?php
  2. $a=$_REQUEST['c0'];
  3. $b=$_REQUEST['c1'];
  4. $c=$_REQUEST['c2'];
  5. $d=$_REQUEST['c3'];
  6. $e=$_REQUEST['c4'];
  7. // content="text/plain; charset=utf-8"
  8. include_once ("jpgraph.php");
  9. include_once ("jpgraph_line.php");
  10.  
  11. // Some random data to plot
  12. $datay=array($a,$b,$c,$d,$e);
  13.  
  14. // Create the graph.
  15. $graph = new Graph(600,400);
  16. $graph->SetScale("textlin");
  17.  
  18. // Create a bar pot
  19. //$bplot = new BarPlot($datay);
  20. $bplot = new LinePlot($datay);
  21. $bplot->SetColor("red");
  22. $bplot->SetWeight(2);
  23. $bplot->SetCenter();
  24. $bplot->mark->SetType(MARK_FILLEDCIRCLE);
  25. $bplot->mark->SetFillColor("red");
  26. $bplot->mark->SetWidth(3);
  27.  
  28. // Create targets for the image maps so that the details are opened in a separate window
  29. $fmtStr = "javascript:window.open('new.php?id=%d&val=%s','_new','width=500,height=300');void(0)";
  30. $n = count($datay);
  31. $targ=array();
  32. $alts=array();
  33. for($i=0; $i < $n; ++$i) {
  34.     $targ[$i] = sprintf($fmtStr,$i+1,$datay[$i]);
  35.     $alts[$i] = 'val=%d';
  36.     // Note: The format placeholder val=%d will be replaced by the actual value in the ouput HTML by the
  37.     // library so that when the user hoovers the mouse over the bar the actual numerical value of the bar
  38.     // will be dísplayed
  39. }
  40. $bplot->SetCSIMTargets($targ,$alts);
  41.  
  42. // Add plot to graph
  43. $graph->Add($bplot);
  44.  
  45. // Setup the title, also wih a CSIM area
  46. $graph->title->Set("CSIM with popup windows");
  47. $graph->title->SetFont(FF_FONT2,FS_BOLD);
  48. // Assume we can give more details on the graph
  49. $graph->title->SetCSIMTarget(sprintf($fmtStr,-1,0),'Title for Bar');
  50.  
  51. // Send back the HTML page which will call this script again to retrieve the image.
  52. $graph->StrokeCSIM();
  53.  
  54. ?>

lo solucione, aunk la respuesta es un poco absurda y me dejo perplejo, antes recuperaba los valores por $_POST y no generaba la grafica; la solucion fue recuperar los valores con $_REQUEST y listo, espero les sirva, esto tardo en solucionar casi 5 meses
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.
Tema Cerrado




La zona horaria es GMT -6. Ahora son las 15:26.