Foros del Web » Programando para Internet » PHP »

Duda usando jpgraph

Estas en el tema de Duda usando jpgraph en el foro de PHP en Foros del Web. Estoy aprndiendo a usar esta libreria. me emontr un tuto que tiene este codigo que genera una grafica de barras. Si me funciona pero lo ...
  #1 (permalink)  
Antiguo 27/10/2007, 21:55
 
Fecha de Ingreso: mayo-2006
Ubicación: Bogotá
Mensajes: 2.061
Antigüedad: 18 años
Puntos: 50
Duda usando jpgraph

Estoy aprndiendo a usar esta libreria. me emontr un tuto que tiene este codigo que genera una grafica de barras. Si me funciona pero lo que no e logrado entender es donde se configuran los valores del eje X el por defecto los tiene de 1 por 1 pero yo creo que debe haber forma de configurarlo saben como se hace?

Código PHP:
<?php
include("inc/jpgraph.php");
include(
"inc/jpgraph_bar.php");
$ydata = array(1138125191357);
$graph = new Graph(350250"auto");    
$graph->SetScale("textlin");
$graph->img->SetMargin(40202040);
$graph->title->Set("JpGraph Demo");
$graph->xaxis->title->Set("Altura" );
$graph->yaxis->title->Set("Total" );
$barplot =new BarPlot($ydata);
$barplot->SetColor("orange");
$graph->Add($barplot);
$graph->Stroke(); 
?>
En esta pagina encontre el codigo y esta la grafica para que entiendan que es lo que quiero hacer.

Código HTML:
http://blog.unijimpe.net/jpgraph-graficos-con-php/
  #2 (permalink)  
Antiguo 27/10/2007, 22:09
Avatar de Carxl
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: Bogotá
Mensajes: 2.993
Antigüedad: 17 años, 9 meses
Puntos: 70
De acuerdo Re: Duda usando jpgraph

Hola Helacer!! Cómo vas??

Mira este es uno de los tantos códigos que he utilizado para generar gráficos de barras:

Código PHP:
<?php
$data1y
=array($tenero,$tfebrero,$tmarzo,$tabril,$tmayo,$tjunio,$tjulio,$tagosto,$tseptiembre,$toctubre,$tnoviembre,$tdiciembre);
$data2y=array($gtenero,$gtfebrero,$gtmarzo,$gtabril,$gtmayo,$gtjunio,$gtjulio,$gtagosto,$gtseptiembre,$gtoctubre,$gtnoviembre,$gtdiciembre);
$datax=array('Ene''Feb','Mar','Abr''May','Jun','Jul','Ago','Sep','Oct','Nov','Dic');

// Create the graph. These two calls are always required
$graph = new Graph(750,350,"auto");    
$graph->SetScale("textlin");

$graph->SetShadow();
$graph->img->SetMargin(100,30,20,40);

//crear leyenda
/*$graph->Legend->Pos(0.02,0.2,"right","center");
$b1plot->SetLegend("Gastos");
$b2plot->SetLegend("Ingresos");*/


// Create the bar plots
$b1plot = new BarPlot($data1y);
$b1plot->SetFillGradient("yellow","red",GRAD_VER);
$b1plot->SetWidth(20);
$b2plot = new BarPlot($data2y);
$b2plot->SetFillGradient("lightsteelblue","navy",GRAD_VER);
$b2plot->SetWidth(20);

//crear leyenda
$graph->legend->Pos(0.02,0.2,"right","center");
$b1plot->SetLegend("Gastos");
$b2plot->SetLegend("Ingresos reales + asignados");



// Create the grouped bar plot
$gbplot = new GroupBarPlot(array($b1plot,$b2plot));

// ...and add it to the graPH
$graph->Add($gbplot);

$graph->title->Set("RELACION GRAFICA INGRESOS - GASTOS AÑO $anno");
$graph->xaxis->title->Set("Mes");
//$graph->yaxis->SetLabelAlign("nter",'center');
$graph->yaxis->title->Set("");

$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->SetTickLabels($datax);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);

$txt=new Text("Valor");
$txt->Pos(10,180);
$txt->SetFont(FF_FONT1,FS_BOLD);
//$txt->SetBox('yellow','navy','gray');
$txt->SetOrientation("v");
$txt->SetColor("black");
$graph->AddText($txt);


// Display the graph
$graph->Stroke();
?>
<img src="graficas.php?ano=<?php echo $anno?>" alt="Relación gráfica ingresos - egresos ejecutados año <?php echo $anno?>">
Fíjate en el array $datax(tercera linea), son los titulos del eje X

Espero te sirva!!, cualquier cosa me dices
__________________
Hay 10 tipos de personas, los que entienden binario y los que no. (Anónimo)
www.programandoweb.com
  #3 (permalink)  
Antiguo 27/10/2007, 22:19
 
Fecha de Ingreso: mayo-2006
Ubicación: Bogotá
Mensajes: 2.061
Antigüedad: 18 años
Puntos: 50
Re: Duda usando jpgraph

Gracias por tan pronta respuesta. Pero aprovechando que usted conoce del tema lo que estoy intentando hacer es de un reporte que genere de una consulta a SQL

generar una grafica de estas. Tiene un codigo de ejemplo que me pueda facilitar oalgo asi?

Gracias de nuevo.
  #4 (permalink)  
Antiguo 27/10/2007, 22:29
Avatar de Carxl
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: Bogotá
Mensajes: 2.993
Antigüedad: 17 años, 9 meses
Puntos: 70
Re: Duda usando jpgraph

Claro si tengo un código que te ayude!!

Lo que pasa es que es un poco largo por que lo hice a la carrera y no es tan óptimo que digamos, lo voy a postear, todo es un mismo archivo, copiar y pegar:

Código PHP:
<?php
require("../../funciones/funciones.php");
include (
"../../funciones/jpgraph/src/jpgraph.php");
include (
"../../funciones/jpgraph/src/jpgraph_bar.php");
include (
"../../funciones/jpgraph/src/jpgraph_canvas.php");


$anno=$_GET[ano];
$i=0;
$link=conexiondb();
if(
$link!=1)
{
do
{
    
    
$consulta="select sum(vlor) from fnnzas_sldas,fnnzas_tpo_srvcio,fnnzas_srvcio where fnnzas_sldas.cdgo_tpo_srvcio=fnnzas_tpo_srvcio.cdgo_tpo_srvcio and fnnzas_tpo_srvcio.cdgo_srvcio=fnnzas_srvcio.cdgo_srvcio and year(fcha_slda)='$anno' and month(fcha_slda)='$i'";    
                
$req=mysql_query($consulta);
                
$row=mysql_fetch_array($req);                
                if(
$i==1)
                    {
                        
$tenero=$row[0];
                    }
                    if(
$i==2)
                    {
                        
$tfebrero=$row[0];
                    }
                    if(
$i==3)
                    {
                        
$tmarzo=$row[0];
                    }
                    if(
$i==4)
                    {
                        
$tabril=$row[0];
                    }
                    if(
$i==5)
                    {
                        
$tmayo=$row[0];
                    }
                    if(
$i==6)
                    {
                        
$tjunio=$row[0];
                    }
                    if(
$i==7)
                    {
                        
$tjulio=$row[0];
                    }
                    if(
$i==8)
                    {
                        
$tagosto=$row[0];
                    }
                    if(
$i==9)
                    {
                        
$tseptiembre=$row[0];
                    }
                    if(
$i==10)
                    {
                        
$toctubre=$row[0];
                    }
                    if(
$i==11)
                    {
                        
$tnoviembre=$row[0];
                    }
                    if(
$i==12)
                    {
                        
$tdiciembre=$row[0];
                    }
                    
$i++;
            }while(
$i<13);
__________________
Hay 10 tipos de personas, los que entienden binario y los que no. (Anónimo)
www.programandoweb.com
  #5 (permalink)  
Antiguo 27/10/2007, 22:30
Avatar de Carxl
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: Bogotá
Mensajes: 2.993
Antigüedad: 17 años, 9 meses
Puntos: 70
De acuerdo Re: Duda usando jpgraph

Código PHP:
<?php
//continuación, coloco la etiqueta <?php para que se entienda que es codigo php, pero debes quitarlaen tu archivo formado
$i=0;        
    
    do
    {    
                
$consulta="select sum(vlor) from fnnzas_entrdas where month(fcha_entrda)='$i' and year(fcha_entrda)='$anno'";    
                
$req=mysql_query($consulta);
                
$row=mysql_fetch_array($req);                
                if(
$i==1)
                    {
                        
$ttenero=$row[0];
                    }
                    if(
$i==2)
                    {
                        
$ttfebrero=$row[0];
                    }
                    if(
$i==3)
                    {
                        
$ttmarzo=$row[0];
                    }
                    if(
$i==4)
                    {
                        
$ttabril=$row[0];
                    }
                    if(
$i==5)
                    {
                        
$ttmayo=$row[0];
                    }
                    if(
$i==6)
                    {
                        
$ttjunio=$row[0];
                    }
                    if(
$i==7)
                    {
                        
$ttjulio=$row[0];
                    }
                    if(
$i==8)
                    {
                        
$ttagosto=$row[0];
                    }
                    if(
$i==9)
                    {
                        
$ttseptiembre=$row[0];
                    }
                    if(
$i==10)
                    {
                        
$ttoctubre=$row[0];
                    }
                    if(
$i==11)
                    {
                        
$ttnoviembre=$row[0];
                    }
                    if(
$i==12)
                    {
                        
$ttdiciembre=$row[0];
                    }
                    
$i++;
            }while(
$i<13);
    
    
$i=0;
    do
            {
                
$consulta="select sum(vlor) from presupuesto_en where mes='$i' and year(fcha_entrda)='$anno'";    
                
$req=mysql_query($consulta);
                
$row=mysql_fetch_array($req);                
                if(
$i==1)
                    {
                        
$gtenero=$row[0]+$ttenero;
                    }
                    if(
$i==2)
                    {
                        
$gtfebrero=$row[0]+$ttfebrero;
                    }
                    if(
$i==3)
                    {
                        
$gtmarzo=$row[0]+$ttmarzo;
                    }
                    if(
$i==4)
                    {
                        
$gtabril=$row[0]+$ttabril;
                    }
                    if(
$i==5)
                    {
                        
$gtmayo=$row[0]+$ttmayo;
                    }
                    if(
$i==6)
                    {
                        
$gtjunio=$row[0]+$ttjunio;
                    }
                    if(
$i==7)
                    {
                        
$gtjulio=$row[0]+$ttjulio;
                    }
                    if(
$i==8)
                    {
                        
$gtagosto=$row[0]+$ttagosto;
                    }
                    if(
$i==9)
                    {
                        
$gtseptiembre=$row[0]+$ttseptiembre;
                    }
                    if(
$i==10)
                    {
                        
$gtoctubre=$row[0]+$ttoctubre;
                    }
                    if(
$i==11)
                    {
                        
$gtnoviembre=$row[0]+$ttnoviembre;
                    }
                    if(
$i==12)
                    {
                        
$gtdiciembre=$row[0]+$ttdiciembre;
                    }
                    
$i++;
            }while(
$i<13);
            
            
}
$data1y=array($tenero,$tfebrero,$tmarzo,$tabril,$tmayo,$tjunio,$tjulio,$tagosto,$tseptiembre,$toctubre,$tnoviembre,$tdiciembre);
$data2y=array($gtenero,$gtfebrero,$gtmarzo,$gtabril,$gtmayo,$gtjunio,$gtjulio,$gtagosto,$gtseptiembre,$gtoctubre,$gtnoviembre,$gtdiciembre);
$datax=array('Ene''Feb','Mar','Abr''May','Jun','Jul','Ago','Sep','Oct','Nov','Dic');

// Create the graph. These two calls are always required
$graph = new Graph(750,350,"auto");    
$graph->SetScale("textlin");

$graph->SetShadow();
$graph->img->SetMargin(100,30,20,40);

//crear leyenda
/*$graph->Legend->Pos(0.02,0.2,"right","center");
$b1plot->SetLegend("Gastos");
$b2plot->SetLegend("Ingresos");*/


// Create the bar plots
$b1plot = new BarPlot($data1y);
$b1plot->SetFillGradient("yellow","red",GRAD_VER);
$b1plot->SetWidth(20);
$b2plot = new BarPlot($data2y);
$b2plot->SetFillGradient("lightsteelblue","navy",GRAD_VER);
$b2plot->SetWidth(20);

//crear leyenda
$graph->legend->Pos(0.02,0.2,"right","center");
$b1plot->SetLegend("Gastos");
$b2plot->SetLegend("Ingresos reales + asignados");



// Create the grouped bar plot
$gbplot = new GroupBarPlot(array($b1plot,$b2plot));

// ...and add it to the graPH
$graph->Add($gbplot);

$graph->title->Set("RELACION GRAFICA INGRESOS - GASTOS AÑO $anno");
$graph->xaxis->title->Set("Mes");
//$graph->yaxis->SetLabelAlign("nter",'center');
$graph->yaxis->title->Set("");

$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->SetTickLabels($datax);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);

$txt=new Text("Valor");
$txt->Pos(10,180);
$txt->SetFont(FF_FONT1,FS_BOLD);
//$txt->SetBox('yellow','navy','gray');
$txt->SetOrientation("v");
$txt->SetColor("black");
$graph->AddText($txt);


// Display the graph
$graph->Stroke();
?>
<img src="graficas.php?ano=<?php echo $anno?>" alt="Relación gráfica ingresos - egresos ejecutados año <?php echo $anno?>">
Espero te sirva
__________________
Hay 10 tipos de personas, los que entienden binario y los que no. (Anónimo)
www.programandoweb.com
  #6 (permalink)  
Antiguo 27/10/2007, 23:56
 
Fecha de Ingreso: mayo-2006
Ubicación: Bogotá
Mensajes: 2.061
Antigüedad: 18 años
Puntos: 50
Re: Duda usando jpgraph

jaja que groseria de codigo pero bueno lo voy a analizar y a meter en mi web a ver si lo logro implementar en la mia

Muchas gracias por la ayuda suerte
  #7 (permalink)  
Antiguo 29/10/2007, 07:01
Avatar de Carxl
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: Bogotá
Mensajes: 2.993
Antigüedad: 17 años, 9 meses
Puntos: 70
De acuerdo Re: Duda usando jpgraph

:-p :-p

__________________
Hay 10 tipos de personas, los que entienden binario y los que no. (Anónimo)
www.programandoweb.com
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




La zona horaria es GMT -6. Ahora son las 09:17.