Subversion Repositories Sites.obs-saisons.fr

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

<?
$jpgraph = "/usr/local/lib/php/jpgraph-1.17";
include ("$jpgraph/jpgraph.php");
include ("$jpgraph/jpgraph_line.php");

include ("../connect.php");

$evenement_id = $_GET['ev'];
$commune_id = $_GET['com'];
$espece_id=$_GET['esp'];

$req_dates = mysql_query("SELECT DATE_FORMAT(MESURE_DATE,'%d%m'), DATE_FORMAT(MESURE_DATE,'%Y') as ANNEE FROM MESURE,SEQUENCE".
        " where SEQUENCE.SEQUENCE_ID=MESURE.SEQUENCE_ID and".
        " EVENEMENT_ID=$evenement_id and ESPECE_ID=$espece_id".
        " AND MESURE_DATE!='0000-00-00'". 
        " and STATION_ID=$commune_id".
        " order by ANNEE");
echo mysql_error();
$dates = array();
$lastannee = 0;
$nbdates = 1;
while ($obs = mysql_fetch_row($req_dates)) {
  $jour_crt = substr($obs[0],0,2);
  $mois_crt = substr($obs[0],2,2);
  $annee_crt = $obs[1];
  if ($obs[1]!=$lastannee) {
    //on calcule la moyenne pour la commune précédente :
    if ($lastannee != 0)
      $dates[$lastannee] = $dates[$lastannee]/$nbdates;
    //on initialise les variables pour la nouvelle commune
    $nbdates = 1;
    $lastannee=$obs[1];
    $dates[$lastannee] = mktime(0,0,0,$mois_crt,$jour_crt);
  } else {
    $nbdates++;
    $dates[$lastannee] += mktime(0,0,0,$mois_crt,$jour_crt);
  }
}
$dates[$lastannee] = $dates[$lastannee]/$nbdates;

if (sizeof($dates)>0) {
  $dateMin = min ($dates);
  $dateMax = max ($dates);
  $nbDates = sizeof ($dates);
}
else {
  $erreurs[] = "Il n'y a pas encore de données cette année pour cette observation.";
}

// Some data
$ydata = array(11,3, 8,12,5 ,1,9, 13,5,7 );

/*foreach ($ydata as $y)
  echo $y;
*/
// Create the graph. These two calls are always required
$graph = new Graph(350, 250,"auto");    
$graph->SetScale( "textint");

$annees = array('2000','2005','2010');
$graph->xaxis->SetTickLabels($annees); 

// Create the linear plot
$lineplot =new LinePlot($ydata);
$lineplot ->SetColor("blue");

// Add the plot to the graph
$graph->Add( $lineplot);

//Un peu de forme
$graph->title->Set("Date de floraison du pommier");
$graph->img->SetMargin(40,20,20,40);
$graph->xaxis->title->Set("Année");
$graph->yaxis->title->Set("Date observée");
 $graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD); 
 $lineplot->mark->SetType(MARK_SQUARE);

// Display the graph
$graph->Stroke(); 
?>