[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 | // Setup the Wind direction graph
|
---|
| 32 | $graph = new Graph(300,800);
|
---|
| 33 | $graph->SetMarginColor('lightgray:1.7');
|
---|
| 34 | $graph->SetScale('datlin',0,360);
|
---|
| 35 | $graph->Set90AndMargin(50,30,60,30);
|
---|
| 36 | $graph->SetFrame(true,'white',0);
|
---|
| 37 | $graph->SetBox();
|
---|
| 38 |
|
---|
| 39 | $graph->title->Set('Wind direction');
|
---|
| 40 | $graph->title->SetFont(FF_ARIAL,FS_BOLD,14);
|
---|
| 41 | $graph->title->SetMargin(10);
|
---|
| 42 |
|
---|
| 43 | $graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,9);
|
---|
| 44 | $graph->xaxis->scale->SetDateFormat('h:i');
|
---|
| 45 | $graph->xgrid->Show();
|
---|
| 46 |
|
---|
| 47 | $graph->yaxis->SetLabelAngle(45);
|
---|
| 48 | $graph->yaxis->SetFont(FF_ARIAL,FS_NORMAL,9);
|
---|
| 49 | $graph->yaxis->SetLabelMargin(0);
|
---|
| 50 | $graph->yaxis->scale->SetAutoMin(0);
|
---|
| 51 |
|
---|
| 52 | $line = new LinePlot($data_winddirection,$xdata);
|
---|
| 53 | $line->SetStepStyle();
|
---|
| 54 | $line->SetColor('blue');
|
---|
| 55 |
|
---|
| 56 | $graph->Add($line);
|
---|
| 57 |
|
---|
| 58 | // Setup the wind speed graph
|
---|
| 59 | $graph2 = new Graph(300,800);
|
---|
| 60 | $graph2->SetScale('datlin');
|
---|
| 61 | $graph2->Set90AndMargin(50,30,60,30);
|
---|
| 62 | $graph2->SetMarginColor('lightgray:1.7');
|
---|
| 63 | $graph2->SetFrame(true,'white',0);
|
---|
| 64 | $graph2->SetBox();
|
---|
| 65 |
|
---|
| 66 | $graph2->title->Set('Windspeed');
|
---|
| 67 | $graph2->title->SetFont(FF_ARIAL,FS_BOLD,14);
|
---|
| 68 | $graph2->title->SetMargin(10);
|
---|
| 69 |
|
---|
| 70 | $graph2->xaxis->SetFont(FF_ARIAL,FS_NORMAL,9);
|
---|
| 71 | $graph2->xaxis->scale->SetDateFormat('h:i');
|
---|
| 72 | $graph2->xgrid->Show();
|
---|
| 73 |
|
---|
| 74 | $graph2->yaxis->SetLabelAngle(45);
|
---|
| 75 | $graph2->yaxis->SetFont(FF_ARIAL,FS_NORMAL,9);
|
---|
| 76 | $graph2->yaxis->SetLabelMargin(0);
|
---|
| 77 | $graph2->yaxis->scale->SetAutoMin(0);
|
---|
| 78 |
|
---|
| 79 | $line2 = new LinePlot($data_windspeed,$xdata);
|
---|
| 80 | $line2->SetStepStyle();
|
---|
| 81 | $line2->SetColor('red');
|
---|
| 82 |
|
---|
| 83 | $graph2->Add($line2);
|
---|
| 84 |
|
---|
| 85 | //-----------------------
|
---|
| 86 | // Create a multigraph
|
---|
| 87 | //----------------------
|
---|
| 88 | $mgraph = new MGraph();
|
---|
| 89 | $mgraph->SetMargin(2,2,2,2);
|
---|
| 90 | $mgraph->SetFrame(true,'darkgray',2);
|
---|
| 91 | $mgraph->SetFillColor('lightgray');
|
---|
| 92 | $mgraph->Add($graph);
|
---|
| 93 | $mgraph->Add($graph2,300,0);
|
---|
| 94 | $mgraph->Stroke();
|
---|
| 95 |
|
---|
| 96 | ?>
|
---|