1 | <?php // content="text/plain; charset=utf-8"
|
---|
2 | require_once ('jpgraph/jpgraph.php');
|
---|
3 | require_once ('jpgraph/jpgraph_line.php');
|
---|
4 | require_once ('jpgraph/jpgraph_date.php');
|
---|
5 | require_once ('jpgraph/jpgraph_mgraph.php');
|
---|
6 |
|
---|
7 | // Setup some fake data to simulate some wind speed and direction
|
---|
8 |
|
---|
9 | DEFINE('NDATAPOINTS',280);
|
---|
10 | DEFINE('SAMPLERATE',300);
|
---|
11 |
|
---|
12 | $start = time();
|
---|
13 | $end = $start+NDATAPOINTS*SAMPLERATE;
|
---|
14 | $xdata = array();
|
---|
15 |
|
---|
16 | $data_winddirection[0] = rand(100,200);
|
---|
17 | $data_windspeed[0] = rand(7,10);
|
---|
18 | $data_windtemp[0] = rand(5,20);
|
---|
19 |
|
---|
20 | for( $i=0; $i < NDATAPOINTS-1; ++$i ) {
|
---|
21 | $data_winddirection[$i+1] = $data_winddirection[$i] + rand(-4,4);
|
---|
22 | if($data_winddirection[$i+1] < 0 || $data_winddirection[$i+1] > 359)
|
---|
23 | $data_winddirection[$i+1] = 0;
|
---|
24 |
|
---|
25 | $data_windspeed[$i+1] = $data_windspeed[$i] + rand(-2,2);
|
---|
26 | if($data_windspeed[$i+1] < 0 )
|
---|
27 | $data_windspeed[$i+1] = 0;
|
---|
28 |
|
---|
29 | $data_windtemp[$i+1] = $data_windtemp[$i] + rand(-1.5,1.5);
|
---|
30 |
|
---|
31 | $xdata[$i] = $start + $i * SAMPLERATE;
|
---|
32 | }
|
---|
33 | $xdata[$i] = $start + $i * SAMPLERATE;
|
---|
34 |
|
---|
35 |
|
---|
36 | //DEFINE('BKG_COLOR','lightgray:1.7');
|
---|
37 | DEFINE('BKG_COLOR','green:1.98');
|
---|
38 | DEFINE('WIND_HEIGHT',800);
|
---|
39 | DEFINE('WIND_WIDTH',250);
|
---|
40 |
|
---|
41 | //------------------------------------------------------------------
|
---|
42 | // Setup the Wind direction graph
|
---|
43 | //------------------------------------------------------------------
|
---|
44 | $graph = new Graph(WIND_WIDTH,WIND_HEIGHT);
|
---|
45 | $graph->SetMarginColor(BKG_COLOR);
|
---|
46 | $graph->SetScale('datlin',0,360);
|
---|
47 | $graph->Set90AndMargin(50,10,70,30);
|
---|
48 | $graph->SetFrame(true,'white',0);
|
---|
49 | $graph->SetBox();
|
---|
50 |
|
---|
51 | $graph->title->Set('Wind direction');
|
---|
52 | $graph->title->SetColor('blue');
|
---|
53 | $graph->title->SetFont(FF_ARIAL,FS_BOLD,14);
|
---|
54 | $graph->title->SetMargin(5);
|
---|
55 |
|
---|
56 | $graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,9);
|
---|
57 | $graph->xaxis->scale->SetDateFormat('H:i');
|
---|
58 | $graph->xgrid->Show();
|
---|
59 |
|
---|
60 | $graph->yaxis->SetLabelAngle(90);
|
---|
61 | $graph->yaxis->SetColor('blue');
|
---|
62 | $graph->yaxis->SetFont(FF_ARIAL,FS_NORMAL,9);
|
---|
63 | $graph->yaxis->SetLabelMargin(0);
|
---|
64 | $graph->yaxis->scale->SetAutoMin(0);
|
---|
65 |
|
---|
66 | $line = new LinePlot($data_winddirection,$xdata);
|
---|
67 | $line->SetStepStyle();
|
---|
68 | $line->SetColor('blue');
|
---|
69 |
|
---|
70 | $graph->Add($line);
|
---|
71 |
|
---|
72 | //------------------------------------------------------------------
|
---|
73 | // Setup the wind speed graph
|
---|
74 | //------------------------------------------------------------------
|
---|
75 | $graph2 = new Graph(WIND_WIDTH-30,WIND_HEIGHT);
|
---|
76 | $graph2->SetScale('datlin');
|
---|
77 | $graph2->Set90AndMargin(5,20,70,30);
|
---|
78 | $graph2->SetMarginColor(BKG_COLOR);
|
---|
79 | $graph2->SetFrame(true,'white',0);
|
---|
80 | $graph2->SetBox();
|
---|
81 |
|
---|
82 | $graph2->title->Set('Windspeed');
|
---|
83 | $graph2->title->SetColor('red');
|
---|
84 | $graph2->title->SetFont(FF_ARIAL,FS_BOLD,14);
|
---|
85 | $graph2->title->SetMargin(5);
|
---|
86 |
|
---|
87 | $graph2->xaxis->HideLabels();
|
---|
88 | $graph2->xgrid->Show();
|
---|
89 |
|
---|
90 | $graph2->yaxis->SetLabelAngle(90);
|
---|
91 | $graph2->yaxis->SetColor('red');
|
---|
92 | $graph2->yaxis->SetFont(FF_ARIAL,FS_NORMAL,9);
|
---|
93 | $graph2->yaxis->SetLabelMargin(0);
|
---|
94 | $graph2->yaxis->scale->SetAutoMin(0);
|
---|
95 |
|
---|
96 | $line2 = new LinePlot($data_windspeed,$xdata);
|
---|
97 | $line2->SetStepStyle();
|
---|
98 | $line2->SetColor('red');
|
---|
99 |
|
---|
100 | $graph2->Add($line2);
|
---|
101 |
|
---|
102 | //------------------------------------------------------------------
|
---|
103 | // Setup the wind temp graph
|
---|
104 | //------------------------------------------------------------------
|
---|
105 | $graph3 = new Graph(WIND_WIDTH-30,WIND_HEIGHT);
|
---|
106 | $graph3->SetScale('datlin');
|
---|
107 | $graph3->Set90AndMargin(5,20,70,30);
|
---|
108 | $graph3->SetMarginColor(BKG_COLOR);
|
---|
109 | $graph3->SetFrame(true,'white',0);
|
---|
110 | $graph3->SetBox();
|
---|
111 |
|
---|
112 | $graph3->title->Set('Temperature');
|
---|
113 | $graph3->title->SetColor('black');
|
---|
114 | $graph3->title->SetFont(FF_ARIAL,FS_BOLD,14);
|
---|
115 | $graph3->title->SetMargin(5);
|
---|
116 |
|
---|
117 | $graph3->xaxis->HideLabels();
|
---|
118 | $graph3->xgrid->Show();
|
---|
119 |
|
---|
120 | $graph3->yaxis->SetLabelAngle(90);
|
---|
121 | $graph3->yaxis->SetColor('black');
|
---|
122 | $graph3->yaxis->SetFont(FF_ARIAL,FS_NORMAL,9);
|
---|
123 | $graph3->yaxis->SetLabelMargin(0);
|
---|
124 | $graph3->yaxis->scale->SetAutoMin(-10);
|
---|
125 |
|
---|
126 | $line3 = new LinePlot($data_windtemp,$xdata);
|
---|
127 | $line3->SetStepStyle();
|
---|
128 | $line3->SetColor('black');
|
---|
129 |
|
---|
130 | $graph3->Add($line3);
|
---|
131 |
|
---|
132 | //-----------------------
|
---|
133 | // Create a multigraph
|
---|
134 | //----------------------
|
---|
135 | $mgraph = new MGraph();
|
---|
136 | $mgraph->SetMargin(2,2,2,2);
|
---|
137 | $mgraph->SetFrame(true,'darkgray',2);
|
---|
138 | $mgraph->SetFillColor(BKG_COLOR);
|
---|
139 | $mgraph->Add($graph,0,50);
|
---|
140 | $mgraph->Add($graph2,250,50);
|
---|
141 | $mgraph->Add($graph3,460,50);
|
---|
142 | $mgraph->title->Set('Climate diagram 12 March 2009');
|
---|
143 | $mgraph->title->SetFont(FF_ARIAL,FS_BOLD,20);
|
---|
144 | $mgraph->title->SetMargin(8);
|
---|
145 | $mgraph->Stroke();
|
---|
146 |
|
---|
147 | ?>
|
---|