1<?php // content="text/plain; charset=utf-8"
2require_once 'jpgraph/jpgraph.php';
3require_once 'jpgraph/jpgraph_line.php';
4
5// Callback to negate the argument
6function _cb_negate($aVal)
7{
8    return round(-$aVal);
9}
10
11// A fake depth curve
12$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);
13
14$n      = count($ydata);
15$y2data = array();
16for ($i = 0; $i < $n; ++$i) {
17    $y2data[] = $ydata[$i] + 10;
18}
19
20// Negate all data
21$n = count($ydata);
22for ($i = 0; $i < $n; ++$i) {
23    $ydata[$i]  = round(-$ydata[$i]);
24    $y2data[$i] = round(-$y2data[$i]);
25}
26
27// Basic graph setup
28$graph = new Graph\Graph(400, 300);
29$graph->SetScale("linlin");
30$graph->SetY2Scale("lin");
31$graph->SetMargin(50, 50, 60, 40);
32$graph->SetMarginColor('darkblue');
33$graph->SetColor('darkblue');
34
35// Setup titles
36$graph->title->Set("Inverting both Y-axis");
37$graph->title->SetFont(FF_FONT1, FS_BOLD);
38$graph->title->SetColor("white");
39
40$graph->subtitle->Set("(Negated Y & Y2 axis)");
41$graph->subtitle->SetFont(FF_FONT1, FS_NORMAL);
42$graph->subtitle->SetColor("white");
43
44// Setup axis
45$graph->yaxis->SetLabelFormatCallback("_cb_negate");
46$graph->xaxis->SetColor("lightblue", "white");
47$graph->yaxis->SetColor("lightblue", "white");
48$graph->ygrid->SetColor("blue");
49
50// Setup Y2 axis
51$graph->y2axis->SetLabelFormatCallback("_cb_negate");
52$graph->y2axis->SetColor("darkred", "white");
53$graph->y2scale->SetAutoMax(0); // To make sure it starts with 0
54
55// Setup plot 1
56$lp1 = new Plot\LinePlot($ydata);
57$lp1->SetColor("yellow");
58$lp1->SetWeight(2);
59$graph->Add($lp1);
60
61// Setup plot 2
62$lp2 = new Plot\LinePlot($y2data);
63$lp2->SetColor("darkred");
64$lp2->SetWeight(2);
65$graph->AddY2($lp2);
66
67$graph->Stroke();
68