[42] | 1 | <?php // content="text/plain; charset=utf-8" |
---|
| 2 | require_once ('jpgraph/jpgraph.php'); |
---|
| 3 | require_once ('jpgraph/jpgraph_line.php'); |
---|
| 4 | |
---|
| 5 | // Callback to negate the argument |
---|
| 6 | function _cb_negate($aVal) { |
---|
| 7 | return round(-$aVal); |
---|
| 8 | } |
---|
| 9 | |
---|
| 10 | // A fake depth curve |
---|
| 11 | $ydata = array(0,1,4,5,8,9,10,14,16,16,16,18,20,20,20,22,22.5,22,19,19,15,15,15,15,10,10,10,6,5,5,5,4,4,2,1,0); |
---|
| 12 | |
---|
| 13 | // Negate all data |
---|
| 14 | $n = count($ydata); |
---|
| 15 | for($i=0; $i<$n; ++$i) { |
---|
| 16 | $ydata[$i] = round(-$ydata[$i]); |
---|
| 17 | } |
---|
| 18 | |
---|
| 19 | // Basic graph setup |
---|
| 20 | $graph = new Graph(400,300); |
---|
| 21 | $graph->SetScale("linlin"); |
---|
| 22 | $graph->img->SetMargin(50,50,60,40); |
---|
| 23 | $graph->SetMarginColor('darkblue'); |
---|
| 24 | $graph->SetColor('darkblue'); |
---|
| 25 | $graph->SetAxisStyle(AXSTYLE_BOXOUT); |
---|
| 26 | |
---|
| 27 | $graph->title->Set("Depth curve. Dive #2"); |
---|
| 28 | $graph->title->SetFont(FF_FONT1,FS_BOLD); |
---|
| 29 | $graph->title->SetColor("white"); |
---|
| 30 | |
---|
| 31 | $graph->subtitle->Set("(Negated Y-axis)"); |
---|
| 32 | $graph->subtitle->SetFont(FF_FONT1,FS_NORMAL); |
---|
| 33 | $graph->subtitle->SetColor("white"); |
---|
| 34 | |
---|
| 35 | // Setup axis |
---|
| 36 | $graph->yaxis->SetLabelFormatCallback("_cb_negate"); |
---|
| 37 | $graph->xaxis->SetColor("lightblue","white"); |
---|
| 38 | $graph->yaxis->SetColor("lightblue","white"); |
---|
| 39 | $graph->ygrid->SetColor("blue"); |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | $lp1 = new LinePlot($ydata); |
---|
| 43 | $lp1->SetColor("yellow"); |
---|
| 44 | $lp1->SetWeight(2); |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | $graph->Add($lp1); |
---|
| 48 | $graph->Stroke(); |
---|
| 49 | ?> |
---|
| 50 | |
---|
| 51 | |
---|