JPGARPH Erreur 25121
mont_dani
Messages postés
232
Date d'inscription
Statut
Membre
Dernière intervention
-
mont_dani Messages postés 232 Date d'inscription Statut Membre Dernière intervention -
mont_dani Messages postés 232 Date d'inscription Statut Membre Dernière intervention -
Bonjour a tous
Après beaucoup de recherhce et de temps passé j ai réussi a preéparér ce script, mais j'ai un problème d'affichage d'un graphique JPGRAPH.
Je suis sous chrome et W8
Le grapique exemple s'affiche très bien, mais quand je passe avec la variable, il affiche un petit carre blanc au milieu d'écran.
Quand je fais un print_r(array_values($ydata)); j'obtient Array ( [0] => 10 [1] => 40 [2] => 5 [3] => 5 [4] => 20 [5] => 91 ).
Merci pour votre coup de main.
Mon script est le suivant.
Après beaucoup de recherhce et de temps passé j ai réussi a preéparér ce script, mais j'ai un problème d'affichage d'un graphique JPGRAPH.
Je suis sous chrome et W8
Le grapique exemple s'affiche très bien, mais quand je passe avec la variable, il affiche un petit carre blanc au milieu d'écran.
Quand je fais un print_r(array_values($ydata)); j'obtient Array ( [0] => 10 [1] => 40 [2] => 5 [3] => 5 [4] => 20 [5] => 91 ).
Merci pour votre coup de main.
Mon script est le suivant.
<?php
session_start ();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<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" />
</head>
<style type="text/css" media="all">
</style>
<body>
<?php
require_once ('jpgraph/src/jpgraph.php');
require_once ('jpgraph/src/jpgraph_line.php');
require_once ('connexion.php');
$_SESSION['mes'] = $_POST['mes'];
$mes_opcion = $_SESSION['mes'];
//$_SESSION['an'] = $_POST['annee'];
//$an_opcion = $_SESSION['an'];
$req = $connexion->prepare('SELECT fecha, lluvia FROM meteo WHERE MONTH(fecha) = ? ');
$req->execute(array($mes_opcion[0]));
$ydata = array();
$indexydata = 0; // init l'index de dépot
// Lecture en boucle des résultats du Query
// Le while boucle tant qu'il y a quelque chose
// et le fetch() avance d'une case à chaque lecture
//$ydata2 = array();
while ($row=$req->fetch(PDO::FETCH_ASSOC))
{
//echo '<li>' . $row['fecha'] . ' ' . $row['lluvia'] . '</li>';
$ydata[$indexydata] = $row['lluvia'];
$indexydata++; // Passe à l'index suivant
}
// 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();
$req->closeCursor();
session_unset ();
session_destroy ();
?>
</body>
</html>
A voir également:
- Content.js:1 uncaught domexception: failed to execute 'getrangeat' on 'selection': 0 is not a valid index.
- Erreur 0x80070643 - Accueil - Windows
- Erreur 0x80070643 Windows 10 : comment résoudre le problème de la mise à jour KB5001716 - Accueil - Windows
- J'aime par erreur facebook notification - Forum Facebook
- Code erreur f3500-31 ✓ - Forum Bbox Bouygues
- Java code erreur 1603 ✓ - Forum Windows
2 réponses
Bonjour,
essayes ça :
NB: J'ai placé le maximum de PHP AVANT le HTML.
Cela rend le code plus lisible et plus facile à maintenir.
NB²: Tu avais des erreurs de balises HTML ( mal placées...)
NB3 : Vu que tu sembles utiliser le PDO, penses à activer la gestion des erreurs comme ceci : https://forums.commentcamarche.net/forum/affich-37584941-php-pdo-gerer-les-erreurs
Cordialement,
Jordane
essayes ça :
<?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(); if(!empty($row)){ //On parcours l'array foreach($row as $R) { $ydata[] = (float)$R['lluvia']; } }else{ echo " La requête n'a pas retournée de données.... "; } $req->closeCursor(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" > <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> <?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(); // 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(); ?> </body> </html>
NB: J'ai placé le maximum de PHP AVANT le HTML.
Cela rend le code plus lisible et plus facile à maintenir.
NB²: Tu avais des erreurs de balises HTML ( mal placées...)
NB3 : Vu que tu sembles utiliser le PDO, penses à activer la gestion des erreurs comme ceci : https://forums.commentcamarche.net/forum/affich-37584941-php-pdo-gerer-les-erreurs
Cordialement,
Jordane
Bon..
déjà :
Tu as sûrement oublié d'initialiser l'index à 1.
Ensuite...
Oulaaaa !!!!
Qu'est-ce que tu fais ????
Que vient faire cette ligne ici :
Tu REMPLACES dans $ydata .. les données par les DATES ???
Non!!
Pour afficher les dates sur ton graphes .. c'est le $xdata qu'il faut remplir et non le ydata.
(le Ydata contient les VALEURS en Y ... et le Xdata... c'est l'absice (l'axe des X) )
Donc :
puis faudra donc faire un
Voir l'exemple ici :
https://jpgraph.net/download/manuals/chunkhtml/ch14s10.html
.
déjà :
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.
Tu as sûrement oublié d'initialiser l'index à 1.
$index=1; foreach($row as $R) { $ydata[$index] = (float)$R['lluvia']; $index ++; }
Ensuite...
Dans
foreach($row as $R) {
$ydata[$index] = (float)$R['lluvia'];
$index ++;
}
j ai fait
foreach($row as $R) {
$ydata[$index] = (float)$R['lluvia'];
$ydata[$index] = (float)$R['fecha'];
$index ++;
}
Oulaaaa !!!!
Qu'est-ce que tu fais ????
Que vient faire cette ligne ici :
$ydata[$index] = (float)$R['fecha'];
Tu REMPLACES dans $ydata .. les données par les DATES ???
Non!!
Pour afficher les dates sur ton graphes .. c'est le $xdata qu'il faut remplir et non le ydata.
(le Ydata contient les VALEURS en Y ... et le Xdata... c'est l'absice (l'axe des X) )
Donc :
$ydata = array(); $xdata = array(); if(!empty($row)){ $index=1; foreach($row as $R) { $ydata[$index] = (float)$R['lluvia']; $xdata[$index] = $R['fecha']; $index ++; } }else{ echo " La requête n'a pas retournée de données.... "; exit(); }
puis faudra donc faire un
$lineplot = new LinePlot($data,$xdata);
Voir l'exemple ici :
https://jpgraph.net/download/manuals/chunkhtml/ch14s10.html
.
juste pour être sûr .... ton fichier est bien en utf8 sans bom ?
Peux tu vérifier (en t'appuyant sur ça : https://forums.commentcamarche.net/forum/affich-37584944-php-html-caracteres-accentues-et-l-utf8#1-verifiez-l-encodage-des-fichiers )
Peux tu vérifier (en t'appuyant sur ça : https://forums.commentcamarche.net/forum/affich-37584944-php-html-caracteres-accentues-et-l-utf8#1-verifiez-l-encodage-des-fichiers )
Je te confirme mon fichier est bien en utf8 sans bom.
connexion.php
<?php
try{
$connexion =new PDO('mysql:host=localhost;
dbname=meteo_test_3; charset=utf8', 'root', '');
// Activation des erreurs PDO
$connexion->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// mode de fetch par défaut : FETCH_ASSOC / FETCH_OBJ / FETCH_BOTH
$connexion->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
} catch(PDOException $e) {
die('Erreur : ' . $e->getMessage());
}
?>
connexion.php
<?php
try{
$connexion =new PDO('mysql:host=localhost;
dbname=meteo_test_3; charset=utf8', 'root', '');
// Activation des erreurs PDO
$connexion->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// mode de fetch par défaut : FETCH_ASSOC / FETCH_OBJ / FETCH_BOTH
$connexion->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
} catch(PDOException $e) {
die('Erreur : ' . $e->getMessage());
}
?>
Donc le fichier est en utf8.
La connexion à la bdd est en utf8 aussi
Ok.
On peut refaire un teste avec ce code ?
Si ça fonctionne... ça vient bien des données transmises par la bdd... et faudra qu'on trouve pourquoi.
Si ça ne fonctionne pas... c'est que ton appel au script n'est pas le bon.
La connexion à la bdd est en utf8 aussi
Ok.
On peut refaire un teste avec ce code ?
<?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>
Si ça fonctionne... ça vient bien des données transmises par la bdd... et faudra qu'on trouve pourquoi.
Si ça ne fonctionne pas... c'est que ton appel au script n'est pas le bon.
Merci pour ta réponse et les modif du script.
La gestion des erreurs etait activée dans connexion.php.
Je continue avec le même probléme. (carré blanc au milieu de l'écran.)
Regarde si tu n'y vois pas une erreur php
si je bloque l'affichage de la ligne ydata (Create the first data series)
j'ai le code suivant:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<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>
JpGraph Error: 25026 Can't draw unspecified Y-scale. You have either: 1. Specified an Y axis for auto scaling but have not supplied any plots. 2. Specified a scale manually but have forgot to specify the tick steps
J ai fait un "inspecter" de la page avec le carre blanc et voici le resultat:
Dans HTML - console j ai erreur suivante
Uncaught DOMException: Failed to execute 'getRangeAt' on 'Selection': 0 is not a valid index.
at file:///C:/Users/PC%20Lenovo/AppData/Local/Google/Chrome/User%20Data/Default/Extensions/fbhgckgfljgjkkfngcoeajbgndkeoaaj/1.0_0/script.js:9:26
2jp_graph.php:1 Error in event handler for (unknown): TypeError: Cannot read property 'farewell' of undefined
Change juste ça pour voir et re-teste