PHP - problema con grafico

 
Vista:
sin imagen de perfil
Val: 557
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

problema con grafico

Publicado por zendi (1056 intervenciones) el 25/11/2014 00:46:42
Tengo este codigo para crear un grafico con la libreria jpgraph.php, pero hay un problema que esta graficando solo tres barras si pudieran ayudarme por favor que no logro captar donde esta el error.

codigo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
include("jpgraph-3.5.0b1/inc/jpgraph.php");
include("jpgraph-3.5.0b1/inc/jpgraph_bar.php");
 
 
$connect = pg_connect("host=localhost port=5432 dbname=pediatria user=postgres password=099012");
$datos = "SELECT peso,talla,circunfcefalica,circunfbrazo,hepatitisa,hepatitisb,meses,anios FROM consulta";
 
$seleccionados = @pg_query($connect,$datos);
 
while($select4 = @pg_fetch_array($seleccionados)):
	 $hepatitisa[] = $select4['peso'];
	 $hepatitisb[] = $select4['talla'];
endwhile;
 
$graph = new Graph("500","400","auto");
 
$graph->SetScale("textint");
 
$graph->img->SetMargin(100,50,20,30);
 
$graph->title->Set("Titulo Grafico");
 
$graph->xaxis->title->Set("Altura");
 
$graph->yaxis->title->Set("Total");
 
$barplot = new BarPlot($hepatitisa);
 
 
$barplot->SetColor("Orange");
$barplot->Setwidth(30);
 
$graph->Add($barplot);
$graph->Stroke();
 
?>
imagen:
grafico

imagen de la tabla:

tabla
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

problema con grafico

Publicado por xve (6935 intervenciones) el 25/11/2014 10:09:53
Hola Zendi, para ello, tienes que jugar los dos array con GroupBarPlot()... aqui te muestro un ejemplo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
include("jpgraph-3.5.0b1/src/jpgraph.php");
include("jpgraph-3.5.0b1/src/jpgraph_bar.php");
 
$hepatitisa=array(5,10,25,30);
$hepatitisb=array(7,5,30,25);
 
$graph = new Graph("500","400","auto");
 
$graph->SetScale("textint");
 
$graph->img->SetMargin(100,50,20,30);
 
$graph->title->Set("Titulo Grafico");
 
$graph->xaxis->title->Set("Altura");
 
$graph->yaxis->title->Set("Total");
 
$barplot1 = new BarPlot($hepatitisa);
$barplot2 = new BarPlot($hepatitisb);
 
$barplot1->SetColor("Orange");
$barplot1->Setwidth(30);
 
$barplot=new GroupBarPlot(array($barplot1,$barplot2));
 
$graph->Add($barplot);
$graph->Stroke();
?>

Coméntanos si te sirve, ok?

jpgraph

Por si a alguien le interesa, puede descargar las librerías de: http://jpgraph.net/download/
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 557
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

problema con grafico

Publicado por zendi (1056 intervenciones) el 25/11/2014 18:01:16
Hola Xve, lo hice de esta manera
pero tengo problemas con los margenes, altura y anchura, no hallo como solventarlo por favor ayudame con esto, lo he modificado en estas propiedades pero no consigo la solucion, y las barras quedan muy pegadas.
ademas de eso ¿Como haria para colocar el peso y la talla por el eje Y?
¿Habria que crear varios query?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
include("jpgraph-3.5.0b1/inc/jpgraph.php");
include("jpgraph-3.5.0b1/inc/jpgraph_bar.php");
$connect = pg_connect("host=localhost port=5432 dbname=pediatria user=postgres password=movilnet");
$datos = "SELECT peso,talla,circunfcefalica,circunfbrazo,hepatitisa,hepatitisb,meses,anios FROM consulta";
 
$seleccionados = @pg_query($connect,$datos);
 
while($select4 = @pg_fetch_array($seleccionados)):
	 $peso = $select4['peso'];
	 $talla = $select4['talla'];
	 $circunfcefalica = $select4['circunfcefalica'];
	 $circunfbrazo = $select4['circunfbrazo'];
	 $hepatitisa = $select4['hepatitisa'];
	 $hepatitisb = $select4['hepatitisb'];
endwhile;
 
$graph = new Graph("500","400","auto");
 
$graph->SetScale("textint");
 
$graph->img->SetMargin(50,20,20,30);
 
$graph->title->Set("Titulo Grafico");
 
$graph->xaxis->title->Set("Altura");
 
$graph->yaxis->title->Set("Total");
 
$barplot1 = new BarPlot($peso);
$barplot2 = new BarPlot($talla);
$barplot3 = new BarPlot($circunfcefalica);
$barplot4 = new BarPlot($circunfbrazo);
$barplot5 = new BarPlot($hepatitisa);
$barplot6 = new BarPlot($hepatitisb);
 
 
$barplot = new GroupBarPlot(array($barplot1,$barplot2,$barplot3,$barplot4,$barplot5,$barplot6));
 
 
$barplot->SetColor("Orange");
$barplot->Setwidth(250);
 
$graph->Add($barplot);
$graph->Stroke();

la imagen se forma asi:

grafico
Comenta por favor ok?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 557
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

problema con grafico

Publicado por zendi (1056 intervenciones) el 26/11/2014 03:11:36
por favor comenten. Saludos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 557
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

problema con grafico

Publicado por zendi (1056 intervenciones) el 26/11/2014 12:25:52
Pudiera alguien que conozca de graficos dar una opinion con respecto a este codigo:

el asunto es que tengo 6 elementos en el arreglo:

$peso = $select4['peso'];
$talla = $select4['talla'];
$circunfcefalica = $select4['circunfcefalica'];
$circunfbrazo = $select4['circunfbrazo'];
$hepatitisa = $select4['hepatitisa'];
$hepatitisb = $select4['hepatitisb'];
y solo esta imprimiendo 5, asimismo como se imprimiria el nombre de cada columna?

Por favor.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
include("jpgraph-3.5.0b1/inc/jpgraph.php");
include("jpgraph-3.5.0b1/inc/jpgraph_bar.php");
 
 
$connect = pg_connect("host=localhost port=5432 dbname=pediatria user=postgres password=movilnet");
$datos = "SELECT peso,talla,circunfcefalica,circunfbrazo,hepatitisa,hepatitisb,meses,anios FROM consulta";
 
$seleccionados = @pg_query($connect,$datos);
 
while($select4 = @pg_fetch_array($seleccionados)):
	 $peso = $select4['peso'];
	 $talla = $select4['talla'];
	 $circunfcefalica = $select4['circunfcefalica'];
	 $circunfbrazo = $select4['circunfbrazo'];
	 $hepatitisa = $select4['hepatitisa'];
	 $hepatitisb = $select4['hepatitisb'];
endwhile;
 
$graph = new Graph(900,350);
 
$graph->SetScale("textlin");
 
//$graph->img->SetMargin(50,20,20,30);
 
$graph->title->Set("Titulo Grafico");
 
$graph->xaxis->title->Set("Altura");
$graph->xgrid->Show();
$graph->xgrid->SetLineStyle("solid");
 
$barplot1 = new BarPlot($peso);
$barplot2 = new BarPlot($talla);
$barplot3 = new BarPlot($circunfcefalica);
$barplot4 = new BarPlot($circunfbrazo);
$barplot5 = new BarPlot($hepatitisa);
$barplot6 = new BarPlot($hepatitisb);
$graph->yaxis->title->Set("Total");
 
$barplot = new GroupBarPlot(array($barplot1,$barplot2,$barplot3,$barplot4,$barplot5,$barplot6));
$graph->xaxis->SetTickLabels(array('Peso'));
 
 
 
$barplot->SetAlign("center");
 
$barplot->SetColor("Orange");
$barplot->Setwidth(250);
 
$graph->Add($barplot);
$graph->Stroke();
 
?>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 557
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

problema con grafico

Publicado por zendi (1056 intervenciones) el 26/11/2014 20:32:17
hola Xve, lo aplicare y comentaré luego.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 557
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

problema con grafico

Publicado por zendi (1056 intervenciones) el 26/11/2014 17:39:03
Por favor amigos comenten......
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar