Subversion Repositories Sites.obs-saisons.fr

Rev

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

Rev Author Line No. Line
1 aurelien 1
<?
2
$jpgraph = "/usr/local/lib/php/jpgraph-1.17";
3
include ("$jpgraph/jpgraph.php");
4
include ("$jpgraph/jpgraph_line.php");
5
 
6
include ("../connect.php");
7
 
8
$evenement_id = $_GET['ev'];
9
$commune_id = $_GET['com'];
10
$espece_id=$_GET['esp'];
11
 
12
$req_dates = mysql_query("SELECT DATE_FORMAT(MESURE_DATE,'%d%m'), DATE_FORMAT(MESURE_DATE,'%Y') as ANNEE FROM MESURE,SEQUENCE".
13
	" where SEQUENCE.SEQUENCE_ID=MESURE.SEQUENCE_ID and".
14
	" EVENEMENT_ID=$evenement_id and ESPECE_ID=$espece_id".
15
	" AND MESURE_DATE!='0000-00-00'".
16
	" and STATION_ID=$commune_id".
17
	" order by ANNEE");
18
echo mysql_error();
19
$dates = array();
20
$lastannee = 0;
21
$nbdates = 1;
22
while ($obs = mysql_fetch_row($req_dates)) {
23
  $jour_crt = substr($obs[0],0,2);
24
  $mois_crt = substr($obs[0],2,2);
25
  $annee_crt = $obs[1];
26
  if ($obs[1]!=$lastannee) {
27
    //on calcule la moyenne pour la commune précédente :
28
    if ($lastannee != 0)
29
      $dates[$lastannee] = $dates[$lastannee]/$nbdates;
30
    //on initialise les variables pour la nouvelle commune
31
    $nbdates = 1;
32
    $lastannee=$obs[1];
33
    $dates[$lastannee] = mktime(0,0,0,$mois_crt,$jour_crt);
34
  } else {
35
    $nbdates++;
36
    $dates[$lastannee] += mktime(0,0,0,$mois_crt,$jour_crt);
37
  }
38
}
39
$dates[$lastannee] = $dates[$lastannee]/$nbdates;
40
 
41
if (sizeof($dates)>0) {
42
  $dateMin = min ($dates);
43
  $dateMax = max ($dates);
44
  $nbDates = sizeof ($dates);
45
}
46
else {
47
  $erreurs[] = "Il n'y a pas encore de données cette année pour cette observation.";
48
}
49
 
50
// Some data
51
$ydata = array(11,3, 8,12,5 ,1,9, 13,5,7 );
52
 
53
/*foreach ($ydata as $y)
54
  echo $y;
55
*/
56
// Create the graph. These two calls are always required
57
$graph = new Graph(350, 250,"auto");
58
$graph->SetScale( "textint");
59
 
60
$annees = array('2000','2005','2010');
61
$graph->xaxis->SetTickLabels($annees);
62
 
63
// Create the linear plot
64
$lineplot =new LinePlot($ydata);
65
$lineplot ->SetColor("blue");
66
 
67
// Add the plot to the graph
68
$graph->Add( $lineplot);
69
 
70
//Un peu de forme
71
$graph->title->Set("Date de floraison du pommier");
72
$graph->img->SetMargin(40,20,20,40);
73
$graph->xaxis->title->Set("Année");
74
$graph->yaxis->title->Set("Date observée");
75
 $graph->title->SetFont(FF_FONT1,FS_BOLD);
76
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
77
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
78
 $lineplot->mark->SetType(MARK_SQUARE);
79
 
80
// Display the graph
81
$graph->Stroke();
82
?>