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_bar.php');
|
---|
5 |
|
---|
6 |
|
---|
7 | function toFahrenheit($aVal) {
|
---|
8 | return round(($aVal*9/5)+32,2);
|
---|
9 | }
|
---|
10 |
|
---|
11 | function toCelcius($aVal) {
|
---|
12 | return round(($aVal-32)*5/9,2);
|
---|
13 | }
|
---|
14 |
|
---|
15 |
|
---|
16 | $datay =array(2,3,8,19,7,17,6,22);
|
---|
17 |
|
---|
18 | // Create the graph.
|
---|
19 | $graph = new Graph(400,280);
|
---|
20 |
|
---|
21 | // Slightly bigger margins than default to make room for titles
|
---|
22 | $graph->SetMargin(50,60,40,45);
|
---|
23 | $graph->SetMarginColor('white');
|
---|
24 |
|
---|
25 |
|
---|
26 | // Setup the scales for X,Y and Y2 axis
|
---|
27 | $graph->SetScale("textlin"); // X and Y axis
|
---|
28 | $graph->SetY2Scale("lin"); // Y2 axis
|
---|
29 |
|
---|
30 | // Overall graph title
|
---|
31 | $graph->title->Set('Synchronized Y & Y2 scales');
|
---|
32 | $graph->title->SetFont(FF_ARIAL,FS_BOLD,12);
|
---|
33 |
|
---|
34 | // Title for X-axis
|
---|
35 | $graph->xaxis->title->Set('Measurement');
|
---|
36 | $graph->xaxis->title->SetMargin(5);
|
---|
37 | $graph->xaxis->title->SetFont(FF_ARIAL,FS_NORMAL,11);
|
---|
38 |
|
---|
39 | // Create Y data set
|
---|
40 | $lplot = new BarPlot($datay);
|
---|
41 | $graph->yaxis->title->Set('Celcius (C)');
|
---|
42 | $graph->yaxis->title->SetMargin(5);
|
---|
43 | $graph->yaxis->title->SetFont(FF_ARIAL,FS_NORMAL,11);
|
---|
44 | // ... and add the plot to the Y-axis
|
---|
45 | $graph->Add($lplot);
|
---|
46 |
|
---|
47 | // Create Y2 scale data set
|
---|
48 | $l2plot = new LinePlot($datay);
|
---|
49 | $l2plot->SetWeight(0);
|
---|
50 | $graph->y2axis->title->Set('Fahrenheit (F)');
|
---|
51 | $graph->y2axis->title->SetMargin(5); // Some extra margin to clear labels
|
---|
52 | $graph->y2axis->title->SetFont(FF_ARIAL,FS_NORMAL,11);
|
---|
53 | $graph->y2axis->SetLabelFormatCallback('toFahrenheit');
|
---|
54 | $graph->y2axis->SetColor('navy');
|
---|
55 |
|
---|
56 | // ... and add the plot to the Y2-axis
|
---|
57 | $graph->AddY2($l2plot);
|
---|
58 |
|
---|
59 | $graph->Stroke();
|
---|
60 | ?>
|
---|