IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques et frameworks PHP Discussion :

[JpGraph] Affichage courbe JPGRAPH avec données $_SESSION


Sujet :

Bibliothèques et frameworks PHP

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Juillet 2015
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Technicien maintenance

    Informations forums :
    Inscription : Juillet 2015
    Messages : 12
    Points : 9
    Points
    9
    Par défaut [JpGraph] Affichage courbe JPGRAPH avec données $_SESSION
    Bonjour je viens vers vous pour une petite aide.

    J'arrive pas à afficher ma courbe avec ma donné de $_SESSION['test3'] = '20,15,23,15';

    Les valeurs s'affiches bien quand ji rentre "
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    graph->title->Set($_SESSION['test3']);
    graph->title->Set($_SESSION['test3']);
    Nom : aa.PNG
Affichages : 628
Taille : 6,7 Ko

    Mais la courbe "ligne 1" ne s'affiche pas avec les données.

    Voila mon code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    54
    55
    56
    57
    58
    59
     
    <?php 
    // content="text/plain; charset=utf-8"
    session_start ();
     
    require_once ('src/jpgraph.php');
    require_once ('src/jpgraph_line.php');
    $datay1 = array($_SESSION['test3']);
    $datay2 = array(12,9,42,8);
    $datay3 = array(5,17,32,24);
     
    // Setup the graph
    $graph = new Graph(300,250);
    $graph->SetScale("textlin");
     
    $theme_class=new UniversalTheme;
     
    $graph->SetTheme($theme_class);
    $graph->img->SetAntiAliasing(false);
    $graph->title->Set('Filled Y-grid');
    $graph->SetBox(false);
    $graph->title->Set($_SESSION['test3']);
    $graph->SetMargin(40,20,36,63);
     
    $graph->img->SetAntiAliasing();
     
    $graph->yaxis->HideZeroLabel();
    $graph->yaxis->HideLine(false);
    $graph->yaxis->HideTicks(false,false);
     
    $graph->xgrid->Show();
    $graph->xgrid->SetLineStyle("solid");
    $graph->xaxis->SetTickLabels(array('A','B','C','D'));
    $graph->xgrid->SetColor('#E3E3E3');
     
    // Create the first line
    $p1 = new LinePlot($datay1);
    $graph->Add($p1);
    $p1->SetColor("#6495ED");
    $p1->SetLegend('Line 1');
     
    // Create the second line
    $p2 = new LinePlot($datay2);
    $graph->Add($p2);
    $p2->SetColor("#B22222");
    $p2->SetLegend('Line 2');
     
    // Create the third line
    $p3 = new LinePlot($datay3);
    $graph->Add($p3);
    $p3->SetColor("#FF1493");
    $p3->SetLegend('Line 3');
     
    $graph->legend->SetFrameWeight(1);
     
    // Output line
    $graph->Stroke();
     
    ?>
    Cordialement je croise les doights pour avoir un peu d'aide.

  2. #2
    Futur Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Juillet 2015
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Technicien maintenance

    Informations forums :
    Inscription : Juillet 2015
    Messages : 12
    Points : 9
    Points
    9
    Par défaut re
    J'ai fait print_r(array_values($datay1)); et ca me donne ca.
    La mise en forme me semble pas bonne ...
    Array ( [0] => 20,15,23,15 )

  3. #3
    Expert éminent sénior
    Avatar de mathieu
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    10 234
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 10 234
    Points : 15 531
    Points
    15 531
    Par défaut
    si vous avez une chaine de caractères, vous pouvez la découper avec la fonction https://php.net/explode

  4. #4
    Membre éclairé Avatar de ypcman
    Homme Profil pro
    Retraité codeur !
    Inscrit en
    Janvier 2011
    Messages
    595
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : Retraité codeur !
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Janvier 2011
    Messages : 595
    Points : 879
    Points
    879
    Par défaut
    J'ai fait print_r(array_values($datay1)); et ca me donne ca.
    La mise en forme me semble pas bonne ...
    Array ( [0] => 20,15,23,15 )
    Effectivement, quand vous faites
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $datay1 = array($_SESSION['test3']);
    vous insérer la chaine de caractères '20,15,23,15' (ça pourrait être 'foo') dans le tableau $datay1, alors que ce vous voulez faire, c'est insérer chaque valeur 20, puis 15, etc. dans le tableau.
    Comme l'indique Mathieu, explode() est fait pour celà :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $datay1 = explode(',' , $_SESSION['test3']);
    va entrer chaque valeur de $_SESSION['test3'] séparée par ',' dans $datay1.

    Au final, cette discussion n'a pas lieu de se trouver dans le topic JpGraph

    Yves.
    Participez vous aussi !
    Message utile
    Discussion résolue

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Juillet 2015
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Technicien maintenance

    Informations forums :
    Inscription : Juillet 2015
    Messages : 12
    Points : 9
    Points
    9
    Par défaut Problème résolu
    Merci Mathieu ça ma aider à comprendre le format de données utiliser par jpgraph et ça m'aidera par la suite.
    Du coup j'ai utilisé une autre méthode pour filtrer les données par date en passant par $_SESSION.

    Je poste mon projet qui fonctionne si ça peut aider d'autre personne.
    Il permet de filtrer les données de température et humidité par date et de créer un graphique JPGRAPH.

    Le rendu :

    Nom : Capture1.PNG
Affichages : 561
Taille : 20,1 Ko

    La base de données :

    Nom : Capture2.PNG
Affichages : 487
Taille : 11,8 Ko

    Code index.php :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    <?php
    // On démarre la session 
    session_start ();
    ?>
     
    <html>
       <head>
    		  <title></title>
    		  <link rel = "stylesheet" type = "text/css" href = "style.css">
       </head>
     
       <body>    
             <form action = "" method = "post">
    			<table>
    			    <tr>
    					<td><label>Sélection date :</label> </td>          
    					<td><input type = "date" name = "dateselect1" id = "dateselect1" /></td>
    					<td><input type = "submit" value ="Rechercher" name = "submit"/></td>
    				</tr>
    			</table>
                <br />
             </form>
     
          <?php
             if(isset($_POST["submit"])){
                $servername = "localhost:3306";
                $username = "root";
                $password = "";
                $dbname = "Projet";
     
                // Create connection
                $conn = new mysqli($servername, $username, $password, $dbname);
     
    			$dateselect1 = $_POST['dateselect1'];
    			$_SESSION['dateselect1'] = $dateselect1  ;
     
                // Check connection
                if ($conn->connect_error) {
                   die("Connection failed: " . $conn->connect_error);
                } 
                $sql = "SELECT * FROM Projettest WHERE DATE_FORMAT(Dateheure, '%Y-%m-%d') ='$dateselect1' ";
     
    			$result = mysqli_query($conn, $sql);
     
             if (mysqli_num_rows($result) > 0) {
    			 echo "<table border='1' cellpadding='5' width='800px'>";
    			 echo "<tr><td>Date :</td><td>Température :</td><td>Humidité :</td></tr>";
                while($row = mysqli_fetch_assoc($result)) {
     
                   echo "<tr><td>" . $row["Dateheure"]. "</td><td><center>" . $row["Temperature"]."</center></td><td><center>" . $row["Humiditer"]."</center></td></tr>";
     
                }
    			echo "</table>";
    			echo '<br />';
    				echo "<iframe src=\"courbe.php?\" height=\"500px\" width=\"800px\"frameborder=\0\"></iframe>";
             } else {
                echo "0 results";
             }
     
     
             mysqli_close($conn);
     
    		 }
     
          ?><?php
     
     
    ?>
     
     
       </body>
    </html>
    Code courbe.php :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    <?php 
    // content="text/plain; charset=utf-8"
    session_start ();
     
    require_once ('src/jpgraph.php');
    require_once ('src/jpgraph_line.php');
     
     
    $dateselect1 = ($_SESSION['dateselect1']);
    $x_axis = array();  
    $y_axis = array();  
    $b_axis = array();
    $i      = 0;  
    $con    = mysqli_connect("localhost", "root", "", "Projet");  
    // Check connection  
    if (mysqli_connect_errno()) {  
        echo "Failed to connect to MySQL: " . mysqli_connect_error();  
    }  
     
    $result = mysqli_query($con, "SELECT * FROM Projettest WHERE DATE_FORMAT(Dateheure, '%Y-%m-%d') = '$dateselect1'");  
    while ($row = mysqli_fetch_array($result)) {  
        $x_axis[$i] = $row["Temperature"];
        $y_axis[$i] = $row["Humiditer"];
    	$b_axis[$i] = $row["Dateheure"];
        $i++;  
    }  
    mysqli_close($con);  
     
     
     
     
    // Setup the graph
    $graph = new Graph(800,500);
    $graph->SetScale("textlin");
     
    $theme_class=new UniversalTheme;
     
    $graph->SetTheme($theme_class);
    $graph->img->SetAntiAliasing(false);
    $graph->title->Set('Filled Y-grid');
    $graph->title->Set($test8);
    $graph->SetBox(false);
     
    $graph->SetMargin(40,20,36,163);
     
    $graph->img->SetAntiAliasing();
     
    $graph->yaxis->HideZeroLabel();
    $graph->yaxis->HideLine(false);
    $graph->yaxis->HideTicks(false,false);
     
    $graph->xgrid->Show();
    $graph->xgrid->SetLineStyle("solid");
    $graph->xaxis->SetTickLabels($b_axis);
    $graph->xgrid->SetColor('#E3E3E3');
     
     
    // Set the angle for the labels to 90 degrees
    $graph->xaxis->SetLabelAngle(90);
     
     
    // Create the first line
    $p1 = new LinePlot($x_axis);
    $graph->Add($p1);
    $p1->SetColor("#6495ED");
    $p1->SetLegend('Température');
     
    // Create the second line
    $p2 = new LinePlot($y_axis);
    $graph->Add($p2);
    $p2->SetColor("#B22222");
    $p2->SetLegend('Humidité');
     
     
     
    $graph->legend->SetFrameWeight(1);
    // Position de la legende
    $graph->legend->SetPos(0.15,0.03,'center','center');
    // Output line
    $graph->Stroke();
    //print_r($test8);
    //print_r(array_values($test8));
    ?>

Discussions similaires

  1. Courbe basique avec données en ligne
    Par Nutella14 dans le forum Power BI
    Réponses: 1
    Dernier message: 14/06/2018, 11h40
  2. [JpGraph] Affichage courbe : JpGraph Error: 25068 A plot has an illegal scale
    Par pauloSE dans le forum Bibliothèques et frameworks
    Réponses: 34
    Dernier message: 09/04/2018, 13h55
  3. [JpGraph] une courbe simple avec jpgraph
    Par deessemba dans le forum Bibliothèques et frameworks
    Réponses: 4
    Dernier message: 29/07/2011, 11h08
  4. affichage de graphique avec données dynamiques
    Par arnest dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 28/04/2008, 13h31
  5. [MySQL] Problème affichage tableau PHP avec données SQL
    Par akalaan dans le forum PHP & Base de données
    Réponses: 4
    Dernier message: 25/04/2006, 14h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo