| 1 |
lars |
1 |
<?php
|
|
|
2 |
// A medium complex example of JpGraph
|
|
|
3 |
// Note: You can create a graph in far fewwr lines of code if you are
|
|
|
4 |
// willing to go with the defaults. This is an illustrative example of
|
|
|
5 |
// some of the capabilities of JpGraph.
|
|
|
6 |
|
|
|
7 |
include ("../jpgraph.php");
|
|
|
8 |
include ("../jpgraph_line.php");
|
|
|
9 |
include ("../jpgraph_bar.php");
|
|
|
10 |
|
|
|
11 |
$month=array(
|
|
|
12 |
"Jan","Feb","Mar","Apr","Maj","Jun","Jul","Aug","Sep","Okt","Nov","Dec");
|
|
|
13 |
|
|
|
14 |
// Create some datapoints
|
|
|
15 |
$steps=100;
|
|
|
16 |
for($i=0; $i<$steps; ++$i) {
|
|
|
17 |
$databarx[]=sprintf("198%d %s",floor($i/12),$month[$i%12]);
|
|
|
18 |
$datay[$i]=log(pow($i,$i/10)+1)*sin($i/15)+35;
|
|
|
19 |
if( $i % 6 == 0 && $i<$steps-6) {
|
|
|
20 |
$databary[]=abs(25*sin($i)+5);
|
|
|
21 |
}
|
|
|
22 |
else {
|
|
|
23 |
$databary[]=0;
|
|
|
24 |
}
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
// New graph with a background image and drop shadow
|
|
|
28 |
$graph = new Graph(450,300,"auto");
|
|
|
29 |
$graph->SetBackgroundImage("tiger_bkg.png",BGIMG_FILLFRAME);
|
|
|
30 |
$graph->SetShadow();
|
|
|
31 |
|
|
|
32 |
// Use text X-scale so we can text labels on the X-axis
|
|
|
33 |
$graph->SetScale("textlin");
|
|
|
34 |
|
|
|
35 |
// Y2-axis is linear
|
|
|
36 |
$graph->SetY2Scale("lin");
|
|
|
37 |
|
|
|
38 |
// Color the two Y-axis to make them easier to associate
|
|
|
39 |
// to the corresponding plot (we keep the axis black though)
|
|
|
40 |
$graph->yaxis->SetColor("black","red");
|
|
|
41 |
$graph->y2axis->SetColor("black","orange");
|
|
|
42 |
|
|
|
43 |
// Set title and subtitle
|
|
|
44 |
$graph->title->Set("Combined bar and line plot");
|
|
|
45 |
$graph->subtitle->Set("100 data points, X-Scale: 'text'");
|
|
|
46 |
|
|
|
47 |
// Use built in font (don't need TTF support)
|
|
|
48 |
$graph->title->SetFont(FF_FONT1,FS_BOLD);
|
|
|
49 |
|
|
|
50 |
// Make the margin around the plot a little bit bigger then default
|
|
|
51 |
$graph->img->SetMargin(40,140,40,80);
|
|
|
52 |
|
|
|
53 |
// Slightly adjust the legend from it's default position in the
|
|
|
54 |
// top right corner to middle right side
|
|
|
55 |
$graph->legend->Pos(0.03,0.5,"right","center");
|
|
|
56 |
|
|
|
57 |
// Display every 6:th tickmark
|
|
|
58 |
$graph->xaxis->SetTextTickInterval(6);
|
|
|
59 |
|
|
|
60 |
// Label every 2:nd tick mark
|
|
|
61 |
$graph->xaxis->SetTextLabelInterval(2);
|
|
|
62 |
|
|
|
63 |
// Setup the labels
|
|
|
64 |
$graph->xaxis->SetTickLabels($databarx);
|
|
|
65 |
$graph->xaxis->SetLabelAngle(90);
|
|
|
66 |
|
|
|
67 |
// Create a red line plot
|
|
|
68 |
$p1 = new LinePlot($datay);
|
|
|
69 |
$p1->SetColor("red");
|
|
|
70 |
$p1->SetLegend("Pressure");
|
|
|
71 |
|
|
|
72 |
// Create the bar plot
|
|
|
73 |
$b1 = new BarPlot($databary);
|
|
|
74 |
$b1->SetLegend("Temperature");
|
|
|
75 |
$b1->SetFillColor("orange");
|
|
|
76 |
$b1->SetAbsWidth(8);
|
|
|
77 |
|
|
|
78 |
// Drop shadow on bars adjust the default values a little bit
|
|
|
79 |
$b1->SetShadow("steelblue",2,2);
|
|
|
80 |
|
|
|
81 |
// The order the plots are added determines who's ontop
|
|
|
82 |
$graph->Add($p1);
|
|
|
83 |
$graph->AddY2($b1);
|
|
|
84 |
|
|
|
85 |
// Finally output the image
|
|
|
86 |
$graph->Stroke();
|
|
|
87 |
|
|
|
88 |
?>
|
|
|
89 |
|
|
|
90 |
|