source: trunk/xgraph/xfelgraph.php @ 42

Last change on this file since 42 was 42, checked in by marrucho, 10 years ago
File size: 5.3 KB
Line 
1<?php // content="text/plain; charset=utf-8"
2require_once ('jpgraph/jpgraph.php');
3require_once ('jpgraph/jpgraph_line.php');
4require_once ('jpgraph/jpgraph_date.php');
5require_once ('jpgraph/jpgraph_mgraph.php');
6
7
8DEFINE('NDATAPOINTS',28000);
9DEFINE('SAMPLERATE',300);
10
11$start = time();
12$end = $start+NDATAPOINTS*SAMPLERATE;
13$xdata_vacuum_1 = array();
14$xdata_vacuum_2 = array();
15$xdata_vacuum_3 = array();
16
17//lecture data base
18$db = mysql_connect('127.0.0.1', 'root', '');   // connexion
19mysql_select_db('xfel',$db);                // selection
20
21$req_vacuum = mysql_query("SELECT v1,v2,v3 FROM vacuum WHERE id_stand='b'");// requetes
22$req_measure = mysql_query("SELECT hour FROM measure");
23 
24$res = mysql_num_rows($req_vacuum);                    // compte le nb d'enregistrements
25//echo 'Il y a '.$res.' enregistrement(s) dans la table xfel : ';// affichage du resultat
26
27// on fait une boucle qui va faire un tour pour chaque enregistrement
28$index=0; 
29while($data=mysql_fetch_assoc($req_vacuum)) 
30    { 
31    $data_vacuum_1[$index] = $data['v1'];
32    $data_vacuum_2[$index] = $data['v2'];
33    $data_vacuum_3[$index] = $data['v3'];
34    $index++;
35    } 
36$index=0;
37while($data=mysql_fetch_assoc($req_measure)) 
38    { 
39    $data_measure[$index] = $data['hour'];
40    $index++;
41    } 
42
43mysql_close($db);// fermeture connexion
44
45
46for( $i=0; $i < $index; ++$i ) {
47  //   echo '(',$i,')' . ' ' . $data_measure[$i] . ' ' . $data_vacuum_1[$i] . ' ' . $data_vacuum_2[$i] . ' ' . $data_vacuum_3[$i] . ' - ' ;
48   $data_temperature[$i] = $data_vacuum_1[$i];
49   $data_vacuum[$i] = $data_vacuum_2[$i];
50   $data_power[$i] = $data_vacuum_3[$i];
51   $xdata[$i] = $data_measure[$i];
52}
53
54
55$xdata[$i] = $start + $i * SAMPLERATE;
56
57//DEFINE('BKG_COLOR','lightgray:1.7');
58DEFINE('BKG_COLOR','green:1.98');
59DEFINE('WIND_HEIGHT',800);
60DEFINE('WIND_WIDTH',250);
61
62
63//------------------------------------------------------------------
64// Setup the V1 vacuum graph
65//------------------------------------------------------------------
66$graph = new Graph(WIND_WIDTH,WIND_HEIGHT);
67$graph->SetMarginColor(BKG_COLOR);
68$graph->SetScale('datlin',0,60);
69$graph->Set90AndMargin(50,10,70,30);
70$graph->SetFrame(true,'white',0);
71$graph->SetBox();
72
73$graph->title->Set('V1');
74$graph->title->SetColor('red');
75$graph->title->SetFont(FF_FONT1,FS_BOLD,48);
76$graph->title->SetMargin(5);
77
78$graph->xaxis->SetFont(FF_FONT0,FS_NORMAL,9);
79
80//$graph->xaxis->scale->SetDateFormat('H:i');
81$graph->xaxis->SetTickLabels($xdata);
82
83$graph->xgrid->Show();
84
85$graph->yaxis->SetLabelAngle(90);
86$graph->yaxis->SetColor('red');
87$graph->yaxis->SetFont(FF_FONT0,FS_NORMAL,9);
88$graph->yaxis->SetLabelMargin(0);
89$graph->yaxis->scale->SetAutoMin(10);
90
91//$line = new LinePlot($data_temperature,$xdata);
92$line = new LinePlot($data_vacuum_1);
93$line->SetStepStyle();
94$line->SetColor('red');
95
96$graph->AddLine($line);
97
98//$graph->Add($line);
99
100//------------------------------------------------------------------
101// Setup the V2 vacuum graph
102//------------------------------------------------------------------
103$graph2 = new Graph(WIND_WIDTH-30,WIND_HEIGHT);
104//$graph2->SetScale('datlin');
105$graph2->SetScale('datlin',0,60);
106$graph2->Set90AndMargin(5,20,70,30);
107$graph2->SetMarginColor(BKG_COLOR);
108$graph2->SetFrame(true,'white',0);
109$graph2->SetBox();
110
111$graph2->title->Set('V2');
112$graph2->title->SetColor('blue');
113$graph2->title->SetFont(FF_FONT1,FS_BOLD,48);
114$graph2->title->SetMargin(5);
115
116$graph2->xaxis->HideLabels();
117$graph2->xgrid->Show();
118
119$graph2->yaxis->SetLabelAngle(90);
120$graph2->yaxis->SetColor('blue');
121$graph2->yaxis->SetFont(FF_FONT0,FS_NORMAL,9);
122$graph2->yaxis->SetLabelMargin(0);
123//$graph2->yaxis->scale->SetAutoMin(50);
124
125//$line2 = new LinePlot($data_vacuum,$xdata);
126$line2 = new LinePlot($data_vacuum_2);
127$line2->SetStepStyle();
128$line2->SetColor('blue');
129
130$graph2->AddLine($line2);
131
132//$graph2->Add($line2);
133
134//------------------------------------------------------------------
135// Setup the V3 vacuum graph
136//------------------------------------------------------------------
137$graph3 = new Graph(WIND_WIDTH-30,WIND_HEIGHT);
138$graph3->SetScale('datlin',0,60);
139$graph3->Set90AndMargin(5,20,70,30);
140$graph3->SetMarginColor(BKG_COLOR);
141$graph3->SetFrame(true,'white',0);
142$graph3->SetBox();
143
144$graph3->title->Set('V3');
145$graph3->title->SetColor('black');
146$graph3->title->SetFont(FF_FONT1,FS_BOLD,48);
147$graph3->title->SetMargin(5);
148
149$graph3->xaxis->HideLabels();
150$graph3->xgrid->Show();
151
152$graph3->yaxis->SetLabelAngle(90);
153$graph3->yaxis->SetColor('black');
154$graph3->yaxis->SetFont(FF_FONT0,FS_NORMAL,9);
155$graph3->yaxis->SetLabelMargin(0);
156$graph3->yaxis->scale->SetAutoMin(-10);
157
158//$line3 = new LinePlot($data_power,$xdata);
159$line3 = new LinePlot($data_vacuum_3);
160$line3->SetStepStyle();
161$line3->SetColor('black');
162
163$graph3->AddLine($line3);
164
165//$graph3->Add($line3);
166
167//-----------------------
168// Create a multigraph
169//----------------------
170$mgraph = new MGraph();
171$mgraph->SetMargin(2,2,2,2);
172$mgraph->SetFrame(true,'darkgray',2);
173$mgraph->SetFillColor(BKG_COLOR);
174$mgraph->Add($graph,0,50);
175$mgraph->Add($graph2,250,50);
176$mgraph->Add($graph3,460,50);
177$mgraph->title->Set('XFEL Stand A August 2013');
178$mgraph->title->SetFont(FF_FONT2,FS_BOLD,80);
179$mgraph->title->SetMargin(8);
180$mgraph->Stroke();
181
182?>
Note: See TracBrowser for help on using the repository browser.