[42] | 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',420); |
---|
| 10 | DEFINE('SAMPLERATE',300); |
---|
| 11 | $start = time(); |
---|
| 12 | $end = $start+NDATAPOINTS*SAMPLERATE; |
---|
| 13 | $data = array(); |
---|
| 14 | $xdata = array(); |
---|
| 15 | $data_winddirection[0] = rand(100,200); |
---|
| 16 | $data_windspeed[0] = rand(7,10); |
---|
| 17 | for( $i=0; $i < NDATAPOINTS-1; ++$i ) { |
---|
| 18 | $data_winddirection[$i+1] = $data_winddirection[$i] + rand(-4,4); |
---|
| 19 | if($data_winddirection[$i+1] < 0 || $data_winddirection[$i+1] > 359) |
---|
| 20 | $data_winddirection[$i+1] = 0; |
---|
| 21 | |
---|
| 22 | $data_windspeed[$i+1] = $data_windspeed[$i] + rand(-2,2); |
---|
| 23 | if($data_windspeed[$i+1] < 0 ) |
---|
| 24 | $data_windspeed[$i+1] = 0; |
---|
| 25 | |
---|
| 26 | $xdata[$i] = $start + $i * SAMPLERATE; |
---|
| 27 | } |
---|
| 28 | $xdata[$i] = $start + $i * SAMPLERATE; |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | DEFINE('BKG_COLOR','lightgray:1.7'); |
---|
| 32 | DEFINE('WIND_HEIGHT',800); |
---|
| 33 | DEFINE('WIND_WIDTH',280); |
---|
| 34 | |
---|
| 35 | // Setup the Wind direction graph |
---|
| 36 | $graph = new Graph(WIND_WIDTH,WIND_HEIGHT); |
---|
| 37 | $graph->SetMarginColor(BKG_COLOR); |
---|
| 38 | $graph->SetScale('datlin',0,360); |
---|
| 39 | $graph->Set90AndMargin(50,10,60,30); |
---|
| 40 | $graph->SetFrame(true,'white',0); |
---|
| 41 | $graph->SetBox(); |
---|
| 42 | |
---|
| 43 | $graph->title->Set('Wind direction'); |
---|
| 44 | $graph->title->SetColor('blue'); |
---|
| 45 | $graph->title->SetFont(FF_ARIAL,FS_BOLD,14); |
---|
| 46 | $graph->title->SetMargin(5); |
---|
| 47 | |
---|
| 48 | $graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,9); |
---|
| 49 | $graph->xaxis->scale->SetDateFormat('h:i'); |
---|
| 50 | $graph->xgrid->Show(); |
---|
| 51 | |
---|
| 52 | $graph->yaxis->SetLabelAngle(90); |
---|
| 53 | $graph->yaxis->SetColor('blue'); |
---|
| 54 | $graph->yaxis->SetFont(FF_ARIAL,FS_NORMAL,9); |
---|
| 55 | $graph->yaxis->SetLabelMargin(0); |
---|
| 56 | $graph->yaxis->scale->SetAutoMin(0); |
---|
| 57 | |
---|
| 58 | $line = new LinePlot($data_winddirection,$xdata); |
---|
| 59 | $line->SetStepStyle(); |
---|
| 60 | $line->SetColor('blue'); |
---|
| 61 | |
---|
| 62 | $graph->Add($line); |
---|
| 63 | |
---|
| 64 | // Setup the wind speed graph |
---|
| 65 | $graph2 = new Graph(WIND_WIDTH-30,WIND_HEIGHT); |
---|
| 66 | $graph2->SetScale('datlin'); |
---|
| 67 | $graph2->Set90AndMargin(5,20,60,30); |
---|
| 68 | $graph2->SetMarginColor(BKG_COLOR); |
---|
| 69 | $graph2->SetFrame(true,'white',0); |
---|
| 70 | $graph2->SetBox(); |
---|
| 71 | |
---|
| 72 | $graph2->title->Set('Windspeed'); |
---|
| 73 | $graph2->title->SetColor('red'); |
---|
| 74 | $graph2->title->SetFont(FF_ARIAL,FS_BOLD,14); |
---|
| 75 | $graph2->title->SetMargin(5); |
---|
| 76 | |
---|
| 77 | $graph2->xaxis->HideLabels(); |
---|
| 78 | $graph2->xgrid->Show(); |
---|
| 79 | |
---|
| 80 | $graph2->yaxis->SetLabelAngle(90); |
---|
| 81 | $graph2->yaxis->SetColor('red'); |
---|
| 82 | $graph2->yaxis->SetFont(FF_ARIAL,FS_NORMAL,9); |
---|
| 83 | $graph2->yaxis->SetLabelMargin(0); |
---|
| 84 | $graph2->yaxis->scale->SetAutoMin(0); |
---|
| 85 | |
---|
| 86 | $line2 = new LinePlot($data_windspeed,$xdata); |
---|
| 87 | $line2->SetStepStyle(); |
---|
| 88 | $line2->SetColor('red'); |
---|
| 89 | |
---|
| 90 | $graph2->Add($line2); |
---|
| 91 | |
---|
| 92 | //----------------------- |
---|
| 93 | // Create a multigraph |
---|
| 94 | //---------------------- |
---|
| 95 | $mgraph = new MGraph(); |
---|
| 96 | $mgraph->SetMargin(2,2,2,2); |
---|
| 97 | $mgraph->SetFrame(true,'darkgray',2); |
---|
| 98 | $mgraph->SetFillColor(BKG_COLOR); |
---|
| 99 | $mgraph->Add($graph); |
---|
| 100 | $mgraph->Add($graph2,280,0); |
---|
| 101 | $mgraph->Stroke(); |
---|
| 102 | |
---|
| 103 | ?> |
---|