[42] | 1 | <?php
|
---|
| 2 | require_once ('jpgraph/jpgraph.php');
|
---|
| 3 | require_once ('jpgraph/jpgraph_windrose.php');
|
---|
| 4 |
|
---|
| 5 | // Data
|
---|
| 6 | $data = array(
|
---|
| 7 | 0 => array(1,1,2.5,4),
|
---|
| 8 | 1 => array(3,4,1,4),
|
---|
| 9 | 3 => array(2,7,4,4,3),
|
---|
| 10 | 5 => array(2,7,1,2));
|
---|
| 11 |
|
---|
| 12 | // Text to be added.
|
---|
| 13 | $txt=array();
|
---|
| 14 | $txt[0] = "It is possible to add arbitrary,multi line, text to a graph. ";
|
---|
| 15 | $txt[0] .= "Such a paragraph can have it's text be left, right or center ";
|
---|
| 16 | $txt[0] .= "aligned.";
|
---|
| 17 | $txt[1] = "This is an example of a right aligned paragraph.";
|
---|
| 18 | $txt[2] = "Finally we can show a center aligned paragraph without box.";
|
---|
| 19 |
|
---|
| 20 | // We store the layout for each of the text boxes in an array
|
---|
| 21 | // to keep the code clean
|
---|
| 22 | $txtlayout = array(
|
---|
| 23 | array(0.97,0.15,25,'left','black','lightblue'),
|
---|
| 24 | array(0.97,0.4,20,'right','black','lightblue'),
|
---|
| 25 | array(0.97,0.7,20,'center','darkred',false,FF_COMIC,FS_NORMAL,12),
|
---|
| 26 | );
|
---|
| 27 |
|
---|
| 28 | // Range colors to be used
|
---|
| 29 | $rangeColors = array('silver','khaki','orange','brown','blue','navy','maroon','red');
|
---|
| 30 |
|
---|
| 31 | // First create a new windrose graph with a title
|
---|
| 32 | $graph = new WindroseGraph(570,430);
|
---|
| 33 | $graph->title->Set('Windrose example 5');
|
---|
| 34 | $graph->title->SetFont(FF_VERDANA,FS_BOLD,12);
|
---|
| 35 | $graph->title->SetColor('navy');
|
---|
| 36 |
|
---|
| 37 | // Setup graph background color
|
---|
| 38 | $graph->SetColor('darkgreen@0.7');
|
---|
| 39 |
|
---|
| 40 | // Setup all the defined text boxes
|
---|
| 41 | $n = count($txt);
|
---|
| 42 | for( $i=0; $i < $n; ++$i ) {
|
---|
| 43 | $txtbox[$i] = new Text($txt[$i]);
|
---|
| 44 | $txtbox[$i]->SetPos($txtlayout[$i][0],$txtlayout[$i][1],'right');
|
---|
| 45 | $txtbox[$i]->SetWordwrap($txtlayout[$i][2]);
|
---|
| 46 | $txtbox[$i]->SetParagraphAlign($txtlayout[$i][3]);
|
---|
| 47 | $txtbox[$i]->SetColor($txtlayout[$i][4]);
|
---|
| 48 | $txtbox[$i]->SetBox($txtlayout[$i][5]);
|
---|
| 49 | if( count($txtlayout[$i]) > 6 )
|
---|
| 50 | $txtbox[$i]->SetFont($txtlayout[$i][6],$txtlayout[$i][7],$txtlayout[$i][8]);
|
---|
| 51 | }
|
---|
| 52 | $graph->Add($txtbox);
|
---|
| 53 |
|
---|
| 54 | // Create the windrose plot.
|
---|
| 55 | $wp = new WindrosePlot($data);
|
---|
| 56 |
|
---|
| 57 | // Set background color for plot area
|
---|
| 58 | $wp->SetColor('lightyellow');
|
---|
| 59 |
|
---|
| 60 | // Add a box around the plot
|
---|
| 61 | $wp->SetBox();
|
---|
| 62 |
|
---|
| 63 | // Setup the colors for the ranges
|
---|
| 64 | $wp->SetRangeColors($rangeColors);
|
---|
| 65 |
|
---|
| 66 | // Adjust the font and font color for scale labels
|
---|
| 67 | $wp->scale->SetFont(FF_ARIAL,FS_NORMAL,9);
|
---|
| 68 | $wp->scale->SetFontColor('navy');
|
---|
| 69 |
|
---|
| 70 | // Set the diameter and position for plot
|
---|
| 71 | $wp->SetSize(190);
|
---|
| 72 | $wp->SetPos(0.35,0.53);
|
---|
| 73 |
|
---|
| 74 | $wp->SetZCircleSize(0.2);
|
---|
| 75 |
|
---|
| 76 | // Adjust the font and font color for compass directions
|
---|
| 77 | $wp->SetFont(FF_ARIAL,FS_NORMAL,10);
|
---|
| 78 | $wp->SetFontColor('darkgreen');
|
---|
| 79 |
|
---|
| 80 | // Adjust the margin to the compass directions
|
---|
| 81 | $wp->SetLabelMargin(50);
|
---|
| 82 |
|
---|
| 83 | // Adjust grid colors
|
---|
| 84 | $wp->SetGridColor('silver','blue');
|
---|
| 85 |
|
---|
| 86 | // Add (m/s) text to legend
|
---|
| 87 | $wp->legend->SetText('(m/s)');
|
---|
| 88 | $wp->legend->SetMargin(20,5);
|
---|
| 89 |
|
---|
| 90 | // Add plot and send back to client
|
---|
| 91 | $graph->Add($wp);
|
---|
| 92 | $graph->Stroke();
|
---|
| 93 | ?>
|
---|
| 94 |
|
---|