Page 1 sur 1

Probleme d'abscisse pour JPGRAPH

Posté : 09 nov. 2005, 14:47
par psaikopat
Bonjour a tous, voila mon petit souci :

j'utilise JpGrapH pour créer des graphique (logique jusque la), mais le problème est que je veux changer les valeurs en abscisse.
Par défault il me met 1, 2, 3, 4, etc ...
J'ai dans une base de donnée des dates. Et donc je voudrai mettre ces dates en abscisses.

Pouvez vous m'aidez ?

Voici mon code, meme si cela ne vous servira pas a grad chose.
<? require_once("./Connections/graph.php"); ?>
<?
$type = $_POST['select'];

$sql = "SELECT ValOrd1 FROM graph.test WHERE TypeGraph = 'STANDARD'"; 
$result = mysql_query($sql);
$tab1 = array(); 
while ($donnees = mysql_fetch_row($result)) { 
$tab1[]=$donnees[0]; 
$data1y=$tab1;
}
$sql = "SELECT ValOrd2 FROM graph.test WHERE TypeGraph = 'STANDARD'"; 
$result = mysql_query($sql);
$tab2 = array(); 
while ($donnees = mysql_fetch_row($result)) { 
$tab2[]=$donnees[0]; 
$data2y=$tab2;
}
$sql = "SELECT ValOrd3 FROM graph.test WHERE TypeGraph = 'STANDARD'"; 
$result = mysql_query($sql);
$tab3 = array(); 
while ($donnees = mysql_fetch_row($result)) { 
$tab3[]=$donnees[0]; 
$data3y=$tab3;
}

include ("./include/jpgraph.php");
include ("./include/jpgraph_bar.php");

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

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

// Create the bar plots
$b1plot = new BarPlot($data1y);
$b1plot->SetFillColor("orange");
$b2plot = new BarPlot($data2y);
$b2plot->SetFillColor("blue");
$b3plot = new BarPlot($data3y);
$b3plot->SetFillColor("green");

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

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

$graph->title->Set("Example 21");
$graph->xaxis->title->Set("X-title");
$graph->yaxis->title->Set("Y-title");

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

// Display the graph
$graph->Stroke();
?>
Merci d'avance ...

Posté : 09 nov. 2005, 14:58
par pitt
Bonjour,

Je ne connais jpgraph mais je me demandais si lorsque tu construis tes tableaux au lieu de mettre juste tes ordonnés tu créais le couple (x,y) il ne le ferait pas automatiquement je te montre (sans aucune garantie mais a essayer)

<? require_once("./Connections/graph.php"); ?> 
<? 
$type = $_POST['select']; 

$sql = "SELECT ValOrd1 , date FROM graph.test WHERE TypeGraph = 'STANDARD'"; 
$result = mysql_query($sql); 
$tab1 = array(); 
while ($donnees = mysql_fetch_row($result)) { 
$couple=array($donnees[0] , $donnees[1]);

$tab1[]=$couple;
$data1y=$tab1; 
} 

include ("./include/jpgraph.php"); 
include ("./include/jpgraph_bar.php"); 

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

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

// Create the bar plots 
$b1plot = new BarPlot($data1y); 
$b1plot->SetFillColor("orange"); 

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

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

$graph->title->Set("Example 21"); 
$graph->xaxis->title->Set("X-title"); 
$graph->yaxis->title->Set("Y-title"); 

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

// Display the graph 
$graph->Stroke(); 
?> 

Essaie ca et dis moi ce que ca te donne (adapte la requete en fonction de ton code)

Posté : 09 nov. 2005, 15:03
par psaikopat
je vois ce que tu veux faire. C'est une bonne idée mais désolé de te décevoir mais cela ne fonctionne pas.
Dommage.
Mais ça aurait été logique !

Posté : 09 nov. 2005, 15:23
par pitt

<? require_once("./Connections/graph.php"); ?> 
<? 
$type = $_POST['select']; 

$sql = "SELECT ValOrd1 , date FROM graph.test WHERE TypeGraph = 'STANDARD'"; 
$result = mysql_query($sql); 
$tab1 = array(); 
$axedesx=array();
while ($donnees = mysql_fetch_row($result)) { 
$tab1[]=$donnees[0]; 
$data1y=$tab1; 
$axedesx[]=$donnees[1];
} 
$sql = "SELECT ValOrd2 FROM graph.test WHERE TypeGraph = 'STANDARD'"; 
$result = mysql_query($sql); 
$tab2 = array(); 
while ($donnees = mysql_fetch_row($result)) { 
$tab2[]=$donnees[0]; 
$data2y=$tab2; 
} 
$sql = "SELECT ValOrd3 FROM graph.test WHERE TypeGraph = 'STANDARD'"; 
$result = mysql_query($sql); 
$tab3 = array(); 
while ($donnees = mysql_fetch_row($result)) { 
$tab3[]=$donnees[0]; 
$data3y=$tab3; 
} 

include ("./include/jpgraph.php"); 
include ("./include/jpgraph_bar.php"); 

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

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

// Create the bar plots 
$b1plot = new BarPlot($data1y); 
$b1plot->SetFillColor("orange"); 
$b2plot = new BarPlot($data2y); 
$b2plot->SetFillColor("blue"); 
$b3plot = new BarPlot($data3y); 
$b3plot->SetFillColor("green"); 

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


$graph->xaxis->SetTickLabels($axedesx);

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

$graph->title->Set("Example 21"); 
$graph->xaxis->title->Set("X-title"); 
$graph->yaxis->title->Set("Y-title"); 

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

// Display the graph 
$graph->Stroke(); 
?> 

Je pense que c'est ca (pas sur)
Si tu veux j'ai trouvé un super site plein d'exemples

http://enacit1.epfl.ch/php/jpgraph/docs ... h.html#4_1

Posté : 09 nov. 2005, 17:04
par psaikopat
Après avoir essayé ton code, voici l'erreur qui surgie :
JpGraph Error: HTTP headers have already been sent.
Explanation:
HTTP headers have already been sent back to the browser indicating the data as text before the library got a chance to send it's image HTTP header to this browser. This makes it impossible for the library to send back image data to the browser (since that would be interpretated as text by the browser and show up as junk text).
Most likely you have some text in your script before the call to Graph::Stroke(). If this texts gets sent back to the browser the browser will assume that all data is plain text. Look for any text, even spaces and newlines, that might have been sent back to the browser.

For example it is a common mistake to leave a blank line before the opening "<?php".
???
Pas évident de trouver ou se trouve l'erreur !!!!

Posté : 09 nov. 2005, 17:08
par pitt
oh
essaie de virer toutes les lignes vides de ton code