Tracer un Histogramme

Par Sanae, il y a 8 ans


Bonjour,

Je suis entrain de développer une petite application pour les statiqtiques , et je veux tracer des diagrammes en fonction des données que j'entre via un formulaire .
j'ai trouvé le code php pour tracer le diagramme , mais j'ai un problème c'est que je n'arrivais pas à modifier les données du diagrammes par es miennes.

Ici la première page ou j'ai le formulaire de saisie , et les calculs:

<?php session_start(); ?> <!DOCTYPE html> <html> <head> <title></title> </head> <body> <form method="post"> <fieldset > <br/> <label for="nom">Nbr Modalites</label> <input type="text" name="nbrM" /> <br /> <input type="submit" value="OK" class="sansLabel" /> <br /> </fieldset> </form> <?php if (isset($_POST['nbrM'])) { $nbrM = $_POST['nbrM']; $_SESSION['nbrM']=$nbrM; ?> <form method="post"> <table> <thead> <tr> <th><label for="Modalités"> Modalites</label></th> <th><label for="Effectifs"> Effectifs</label></th> </tr> </thead> </tbody> <?php for ($i = 0; $i < $nbrM; $i++) { ?> <tr> <td><input type="text" name="nbr[]"></td> <td><input type="text" name="Ef[]"></td> </tr><?php }?> </tbody> </table> <br/> <input type="submit" value="OK" class="sansLabel" /> <br /> </form><?php } if (isset($_POST['nbr']) && isset($_POST['Ef'])) { $Md = $_POST['nbr']; $Ef = $_POST['Ef']; $_SESSION['Tbmodalite']= $Md; $_SESSION['Tbeffictif']= $Ef; ?> <br><br><br> <table border="solid"> <thead> <tr> <th><label for="Modalités"> Modalites</label></th> <th><label for="Effectifs"> Effectifs</label></th> <th><label for="Effectifs"> Fréquence(%)</label></th> <th><label for="Effectifs"> Fréquence cummulée(%)</label></th> </tr> </thead> <tbody> <?php $somme=0; $Tfi=0; $fiC=0; for ($i=0; $i <$_SESSION['nbrM']; $i++) { $somme=$somme+$Ef[$i];} for ($i=0; $i <$_SESSION['nbrM']; $i++) { $fi=number_format(($Ef[$i]/$somme)*100,4); $Tfi=$fi+$Tfi; $fiC=$fi+$fiC; ?> <tr> <td><?php echo $Md[$i];?></td> <td><?php echo $Ef[$i];?></td> <td><?php echo "$fi" ;?></td> <td><?php echo "$fiC" ;?></td> </tr><?php }?> <tr> <td>Total :</td> <td><?php echo "$somme";?></td> <td><?php echo "$Tfi";?></td> <td> - </td> </tr> </tbody> </table> <br><br><br> <form method="post" action="statistique.php"> <input type="submit" name="graph" value="tracer diagramme "> </form> <?php } ?> </body> </html>

Et pour le code du diagramme:

<?php session_start(); $Md=$_SESSION['Tbmodalite']; $Ef=$_SESSION['Tbeffictif']; require_once ('jpgraph/src/jpgraph.php'); require_once ('jpgraph/src/jpgraph_bar.php'); $datay=array(62,100,105,40); echo $datay; // Create the graph. These two calls are always required $graph = new Graph(350,220,'auto'); $graph->SetScale("textlin"); //$theme_class="DefaultTheme"; //$graph->SetTheme(new $theme_class()); // set major and minor tick positions manually $graph->yaxis->SetTickPositions(array(0,30,60,90,120,150), array(15,45,75,105,135)); $graph->SetBox(false); //$graph->ygrid->SetColor('gray'); $graph->ygrid->SetFill(false); $graph->xaxis->SetTickLabels($Md); $graph->yaxis->HideLine(false); $graph->yaxis->HideTicks(false,false); // Create the bar plots $b1plot = new BarPlot($datay); // ...and add it to the graPH $graph->Add($b1plot); $b1plot->SetColor("white"); $b1plot->SetFillGradient("#4B0082","white",GRAD_LEFT_REFLECTION); $b1plot->SetWidth(45); $graph->title->Set("Bar Gradient(Left reflection)"); // Display the graph $graph->Stroke(); ?>

Et moi je veux remplacer:

$datay=array(62,100,105,40);

par les données de la première page, voilà ce que j'ai fait :

$array="array("; for ($i=0; $i <$_SESSION['nbrM']-1 ; $i++) { $array2="$Ef[$i]".","; } $f=$_SESSION['nbrM']-1; $array3="$Ef[$f]".")"; //echo $array. $array2. $array3; $datay=$array. $array2. $array3; echo $datay;

les valeurs de $datay s'affiche correctement , mais j'ai cette erreur à l'exécution:
Your manually specified scale and ticks is not correct. The scale seems to be too small to hold any of the specified tick marks.
Avez- vous des solutions pour ce problème?
Merci beaucoup d'avance.

1 réponse

Flo.S, il y a 8 ans

Hello,

Arrête moi si je me trompe ... Mais depuis quand PHP t'autorise à créer des tableaux de cette manière ?

$array="array(";

Est-tu sur de connaitre php ? Ou tu fonctionne uniquement par copier/coller ? Car dans ce cas précis, c'est un peu du "n'importe quoi".

Je t'invite à regarder la documentation concernant les arrays() : http://php.net/manual/fr/function.array.php