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] Affiche un carre blanc


Sujet :

Bibliothèques et frameworks PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2017
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vienne (Poitou Charente)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2017
    Messages : 5
    Par défaut [JpGraph] Affiche un carre blanc
    Bonjour a tous.

    J'ai un formulaire qui envoi une varaible a un script pour creer un graphique.

    Lorsque j'utilise le script exemple de JPGRAPH, je graphique s'affiche correctement.
    Quand j'intègre le scrip exemple dans mon script, c est un carre blanc qui s'affiche.

    La requete renvoi bien les données de la BDD.
    print_r(array_values($ydata));
    Array ( [0] => 10 [1] => 40 [2] => 5 [3] => 5 [4] => 20 [5] => 91 ) qui est parfaitement correct avec la BD.

    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
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    <?php
    //Démarrage des sessions
    session_start ();
     
    //Affichage des erreurs PHP
    error_reporting(E_ALL);
    ini_set('display-errors','on');
     
     
    // REQUIRE
    require_once ('jpgraph/src/jpgraph.php');
    require_once ('jpgraph/src/jpgraph_line.php');
    require_once ('connexion.php');
     
     
    //Récupération PROPRE des variables AVANT de les utiliser
    $mes_opcion  = !empty($_POST['mes']) ? $_POST['mes'] : (!empty($_SESSION['mes']) ? $_SESSION['mes'] : NULL);
    $_SESSION['mes'] = $mes_opcion ;
     
     
    //Traitement
    $sql = 'SELECT fecha, lluvia FROM meteo WHERE MONTH(fecha) = ? ';
    $datas = array($mes_opcion[0]);
    try{
      $req = $connexion->prepare($sql);
      $req->execute($datas);
      $row = $req->fetchAll(PDO::FETCH_ASSOC); //on stocke les données dans un ARRAY
    }catch(Exception $e){
      echo "Erreur ! ".$e->getMessage();
    }
     
    $ydata = array();
    //$xdata = array();
     
    if(!empty($row)){
      $index=1;
      foreach($row as $R)  {
        $ydata[$index] = intval($R['lluvia']);
        //$xdata[$index] = $R['fecha']; 
        $index ++;
      }
    }else{
      echo " La requête n'a pas retournée de données.... ";
      print_r($datas);
      exit();
    }
     
    $req->closeCursor();
     
     
    //$ydata = array(11, 3, 8, 12, 5, 1, 9, 13, 5, 7);
     
    ?>
    <!DOCTYPE>
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html" />       
        <meta charset="UTF-8">       
        <link rel="stylesheet" href="general.css" type="text/css" media="screen"/>
        <link rel="stylesheet" href="print.css" type="text/css" media="print" />       
        <style type="text/css" media="all">
        </style>
       </head>
       <body>
        <div id="graphique">
        <?php
     
        // Size of the overall graph
        $width=350;
        $height=250;
     
        // Create the graph and set a scale.
        // These two calls are always required
        $graph = new Graph($width,$height);
        $graph->SetScale('intlin');
        $graph->SetShadow();
        $graph->img->SetAntiAliasing(); 
        // Setup margin and titles
        $graph->SetMargin(40,20,20,40);
        $graph->title->Set('Calls per operator (June,July)');
        $graph->subtitle->Set('(March 12, 2008)');
        $graph->xaxis->title->Set('Operator');
        $graph->yaxis->title->Set('# of calls');
     
        $graph->yaxis->title->SetFont( FF_FONT1 , FS_BOLD );
        $graph->xaxis->title->SetFont( FF_FONT1 , FS_BOLD );
     
     
     
        // Create the first data series
        $lineplot=new LinePlot($ydata);
        $lineplot->SetWeight(2);   // Two pixel wide
     
        // Add the plot to the graph
        $graph->Add($lineplot);
     
        // Display the graph
        $graph->Stroke();
        ?>
        </div>
      </body>
    </html>
    Merci par avance pour votre aide

  2. #2
    Membre Expert
    Avatar de badaze
    Homme Profil pro
    Chef de projets info
    Inscrit en
    Septembre 2002
    Messages
    1 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Chef de projets info
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2002
    Messages : 1 412
    Par défaut
    Et le script d'exemple il ressemble à quoi ?

  3. #3
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2017
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vienne (Poitou Charente)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2017
    Messages : 5
    Par défaut
    Citation Envoyé par badaze Voir le message
    Et le script d'exemple il ressemble à quoi ?
    Le script exemple est:
    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
     
    <?php // content="text/plain; charset=utf-8"
    require_once ('jpgraph/jpgraph.php');
    require_once ('jpgraph/jpgraph_line.php');
     
     // Some (random) data
    $ydata   = array(11, 3, 8, 12, 5, 1, 9, 13, 5, 7);
    $ydata2  = array(1, 19, 15, 7, 22, 14, 5, 9, 21, 13 );
     
    // Size of the overall graph
    $width=350;
    $height=250;
     
    // Create the graph and set a scale.
    // These two calls are always required
    $graph = new Graph($width,$height);
    $graph->SetScale('intlin');
    $graph->SetShadow();
     
    // Setup margin and titles
    $graph->SetMargin(40,20,20,40);
    $graph->title->Set('Calls per operator (June,July)');
    $graph->subtitle->Set('(March 12, 2008)');
    $graph->xaxis->title->Set('Operator');
    $graph->yaxis->title->Set('# of calls');
     
    $graph->yaxis->title->SetFont( FF_FONT1 , FS_BOLD );
    $graph->xaxis->title->SetFont( FF_FONT1 , FS_BOLD );
     
    // Create the first data series
    $lineplot=new LinePlot($ydata);
    $lineplot->SetWeight( 2 );   // Two pixel wide
     
    // Add the plot to the graph
    $graph->Add($lineplot);
     
    // Create the second data series
    $lineplot2=new LinePlot($ydata2);
    $lineplot2->SetWeight( 2 );   // Two pixel wide
     
    // Add the second plot to the graph
    $graph->Add($lineplot2);
     
    // Display the graph
    $graph->Stroke();
    ?>

  4. #4
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Tu ne peux pas avoir dans le même document le graphique et le contenu HTML.
    La génération du graphique doit aller dans un script à lui tout seul.
    La partie HTML appelle le graphique avec la balise <img>
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <img src="mongraphique.php" />
    Au passage n'enchaine pas de opérateurs ternaires comme ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $mes_opcion  = !empty($_POST['mes']) ? $_POST['mes'] : (!empty($_SESSION['mes']) ? $_SESSION['mes'] : NULL);
    C'est illisible et source d'erreur de logique.
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  5. #5
    Membre Expert
    Avatar de badaze
    Homme Profil pro
    Chef de projets info
    Inscrit en
    Septembre 2002
    Messages
    1 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Chef de projets info
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2002
    Messages : 1 412
    Par défaut
    Je ne connais pas cette librairie mais il s'agit sûrement d'un problème de header. Généralement les images générées par php doivent l'être dans un script à part.
    Ensuite dans la page "principale" on met <img src="mon_script.php?param1=1&param2=2"/> et l'image s'affiche.
    Dans le script qui crée l'image, <?php doit commencer au premier caractère de la première ligne. En fait le moindre caractère qui serait situé avant <?php serait envoyé au navigateur et ça ne fonctionnerait pas.

    Voici un exemple de génération d'image dynamique.

    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
     
    <!doctype html>
    <html lang="fr">
    <head>
    <meta charset="utf-8">
     <title>Mes fonds</title>
    </head>
    <body>
    Noir :<br/>
     <img src="mon_image.php?rouge=0&vert=0&bleu=0"/><br>
    Rouge :<br/>
     <img src="mon_image.php?rouge=255&vert=0&bleu=0"/><br> 
    Vert :<br/>
     <img src="mon_image.php?rouge=0&vert=255&bleu=0"/><br> 
    Bleu :<br/>
     <img src="mon_image.php?rouge=0&vert=0&bleu=255"/><br>   
    </body>
    </html>
    mon_image.php
    Code php : 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
    <?php
            header('Content-type: image/png');
      $rouge = $_GET['rouge'];
      $vert  = $_GET['vert'];
      $bleu  = $_GET['bleu'];
     
            $largeur=350;
            $hauteur=100;
            //Création de l'image
            $courbe=imagecreatetruecolor($largeur, $hauteur);
            $fond  = imagecolorallocate($courbe, $rouge, $vert, $bleu);
     
            //Colorier le fond
            imagefilledrectangle($courbe,0 , 0, $largeur, $hauteur, $fond);  //Envoyer le flux de l'image
      imagepng($courbe);
      //Desallouer le memoire utiliser par l'image
      imagedestroy($courbe);   
    ?>

    Donne :
    Nom : 20170609_001.JPG
Affichages : 674
Taille : 23,2 Ko

  6. #6
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2017
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vienne (Poitou Charente)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2017
    Messages : 5
    Par défaut
    Désolé pour autant de temps passé a résoudre ce problème.

    En réalité la bibliothèque JPGRAPH ne fonctionne pas sous X64.

    Merci pour votre aide.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Traitement d'image] Favicon et carré blanc
    Par axel119 dans le forum Webdesign & Ergonomie
    Réponses: 6
    Dernier message: 07/03/2008, 18h14
  2. carré blanc sur le bureau
    Par Mangacker dans le forum Windows Vista
    Réponses: 3
    Dernier message: 28/11/2007, 22h06
  3. Réponses: 3
    Dernier message: 04/04/2007, 11h25
  4. Méthode rapide pour afficher des carré de couleur
    Par matteli dans le forum DirectX
    Réponses: 7
    Dernier message: 03/12/2006, 19h50
  5. [JpGraph] Afficher le symbole "%" ?
    Par Metallic-84s dans le forum Bibliothèques et frameworks
    Réponses: 3
    Dernier message: 22/09/2006, 15h57

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