Probleme insertion image dans jpgrapf

Petit nouveau ! | 9 Messages

16 janv. 2013, 12:50

Bonjour je n arrive pas à integrer une image de fond dans ma courbe quelqu'un peut m aider ?

Voici le code que j utilise
<?php function newLineGraph($cachefilename, $ydata, $xdata)
{
 require_once ('src/jpgraph.php');
 require_once ('src/jpgraph_line.php');
 require_once ('src/jpgraph_utils.inc.php');
 require_once ('src/jpgraph_date.php');
 // First we create the graph with a size of 600 x 500. 
 $graph = new Graph(1000, 800);
 
 // Check if the image already exists in the cache and is valid
 $valid = $graph -> cache -> IsValid($cachefilename);
 if ($valid)
 {
  // The cached file exists and has not expired, so we do not 
  // need to create a new one
  return;
 }
 else
 {
  // The cache file does not exists or has expired, so we
  // create the graph as normal
 
  // Tell the graph that we want to cache this image
  // with a timeout of 60
  $graph -> SetupCache($cachefilename, 60);
  //Set the scale to use DateScale
  $graph -> SetScale("datlin");
  //Set the text for the graph Title
  $nom = $_GET['n_ident'];
  $graph -> title -> Set("Courbe de croissance $nom");
  //Enable clipping to prevent the line from extending
  // outside of the plot area
  $graph -> SetClipping(true);
  // Set the date format to use for the date labels
  $graph -> xaxis -> scale -> SetDateFormat('d-M-Y');
  // inclinason date
  $graph->xaxis->SetTickLabels($datax);
$graph->xaxis->SetLabelAngle(90);
  // Since we're taking in dates from MySQL, we need to
  // convert them to time
 
  $graph->xaxis->title->Set("Date" );
  
$graph->yaxis->title->Set("Poids en grammes" );
$xDates = array ();
  for ($i = 0; $i < sizeof($xdata); $i++)
  {
   $time = strtotime($xdata[$i]);
   array_push($xDates, $time);
  }
  $dateUtils = new DateScaleUtils();
  // We'll let getAutoTicks calculate all of the ticks between
  // our min and max dates. We also set the max number of
  // ticks to 5.'
  $autoTicks = $dateUtils -> getAutoTicks($xDates[0],
 $xDates[sizeof($xDates) - 1], 10);
  // Se the tick positions to the ones returned by getAutoTicks
  $graph -> xaxis -> SetTickPositions($autoTicks[1]);
  // Now we create the actual plot line
  $lineplot = new LinePlot($ydata, $xDates);
  $lineplot -> SetLegend( 'courbe');
  
  // Add the plot line to the graph
  $graph -> Add($lineplot);
  $graph->SetBackgroundImage("LOGO900NEON.png",BGIMG_FILLPLOT);
 
 $graph->img->SetAntiAliasing("white");
 // Get the filepath where the cache file will be saved
  // NOTE: You MUST specify an absolute filepath here,
  // for example '/myCacheFiles/filename' will not work
  $absolutePath = (CACHE_DIR . "" . $cachefilename);
  // And finally, set the filepath when we call the Stroke function
  $graph -> Stroke($absolutePath);
 }
}

//$ydata = array ( 11, 12, 11, 10, 10.5);
//$xdata = array ('2010-07-01', '2010-07-02', '2010-07-03','2010-07-04', '2010-07-09');

$filename = 'myFile.png';
$graph = newLineGraph($filename, $ydata, $xdata);
?>
Voici la page ou ce trouve la courbe avec le code ci dessus ==> http://www.repro-reptiles.com/reptiles/ ... dent=PG001

Avatar du membre
Modérateur PHPfrance
Modérateur PHPfrance | 8758 Messages

16 janv. 2013, 13:06

salut,


est tu sur du chemin vers le fichier ? (le script appelant est bien a la racine ?)

a priori ton code est bon, as tu essayé sans la génération de donnée ? (juste la création du graph + le background ?)

initialiser le background au début ?

@+
Il en faut peu pour être heureux ......

Petit nouveau ! | 9 Messages

16 janv. 2013, 13:22

Je viens de remplacer dans cette ligne $graph->SetBackgroundImage("LOGO900NEON.png",BGIMG_FILLPLOT); FILLPLOT par Copy et on voit Juste un morceau de l image derrière.

En fait après plusieurs essais il faudrait juste avancer l image car elle se trouve derriere

Petit nouveau ! | 9 Messages

16 janv. 2013, 14:47

Je viens de remetre le code a jour
<?php function newLineGraph($cachefilename, $ydata, $xdata)
{
 require_once ('src/jpgraph.php');
 require_once ('src/jpgraph_line.php');
 require_once ('src/jpgraph_utils.inc.php');
 require_once ('src/jpgraph_date.php');
 // First we create the graph with a size of 600 x 500. 
 $graph = new Graph(1000, 800);
   $graph->SetBackgroundImage("fond.png",BGIMG_COPY,'auto');
   $graph->SetBackgroundImageMix(100);
 
 $graph->img->SetAntiAliasing("white");
 // Check if the image already exists in the cache and is valid
 $valid = $graph -> cache -> IsValid($cachefilename);
 if ($valid)
 {
  // The cached file exists and has not expired, so we do not 
  // need to create a new one
  return;
 }
 else
 {
  // The cache file does not exists or has expired, so we
  // create the graph as normal
 
  // Tell the graph that we want to cache this image
  // with a timeout of 60
  $graph -> SetupCache($cachefilename, 60);
  //Set the scale to use DateScale
  $graph -> SetScale("datlin");
   $graph->legend->SetPos(0.5,0.98,'center','bottom');
  //Set the text for the graph Title
  $nom = $_GET['n_ident'];
  $graph -> title -> Set("Courbe de croissance de $nom");
  //Enable clipping to prevent the line from extending
  // outside of the plot area
  $graph -> SetClipping(true);
  // Set the date format to use for the date labels
  $graph -> xaxis -> scale -> SetDateFormat('d-M-Y');
  // inclinason date
  $graph->xaxis->SetTickLabels($datax);
$graph->xaxis->SetLabelAngle(90);
  // Since we're taking in dates from MySQL, we need to
  // convert them to time
 
  $graph->xaxis->title->Set("Date" );
  
$graph->yaxis->title->Set("Poids en grammes" );
$xDates = array ();
  for ($i = 0; $i < sizeof($xdata); $i++)
  {
   $time = strtotime($xdata[$i]);
   array_push($xDates, $time);
  }
  $dateUtils = new DateScaleUtils();
  // We'll let getAutoTicks calculate all of the ticks between
  // our min and max dates. We also set the max number of
  // ticks to 5.'
  $autoTicks = $dateUtils -> getAutoTicks($xDates[0],
 $xDates[sizeof($xDates) - 1], 10);
  // Se the tick positions to the ones returned by getAutoTicks
  $graph -> xaxis -> SetTickPositions($autoTicks[1]);
  // Now we create the actual plot line
  $lineplot = new LinePlot($ydata, $xDates);
  $lineplot -> SetLegend( "courbe du poids de $nom");
 
  // Add the plot line to the graph
  $graph -> Add($lineplot);

 // Get the filepath where the cache file will be saved
  // NOTE: You MUST specify an absolute filepath here,
  // for example '/myCacheFiles/filename' will not work
  $absolutePath = (CACHE_DIR . "" . $cachefilename);
  // And finally, set the filepath when we call the Stroke function
  $graph -> Stroke($absolutePath);
 }
}

//$ydata = array ( 11, 12, 11, 10, 10.5);
//$xdata = array ('2010-07-01', '2010-07-02', '2010-07-03','2010-07-04', '2010-07-09');

$filename = 'myFile.png';
$graph = newLineGraph($filename, $ydata, $xdata);
?>
Donc j ai changer les taille de l'image pour quelle soit égale a la taille du graphique et la ca s affiche maintenant je pense que j ai un problème du genre transparrence

Petit nouveau ! | 9 Messages

16 janv. 2013, 17:12

Je viens de faire un essais avec le code de cette page => http://enacit1.epfl.ch/php/jpgraph/src/ ... ndex02.php

J ai juste remplacer l image par la mienne et cela fais la même erreur que pour mon graphique ==> http://www.repro-reptiles.com/reptiles/test.php

Cela peut venir de quoi ?

Petit nouveau ! | 9 Messages

18 janv. 2013, 23:32

Bonsoir je n est toujours pas trouver de solution quelqu un aurait une idée ?