Blame view

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