source: trunk/xgraph/jpgraph/Examples/linebarex1.php @ 42

Last change on this file since 42 was 42, checked in by marrucho, 10 years ago
File size: 1.9 KB
Line 
1<?php // content="text/plain; charset=utf-8"
2require_once ('jpgraph/jpgraph.php');
3require_once ('jpgraph/jpgraph_line.php');
4require_once ('jpgraph/jpgraph_bar.php');
5
6$month=array(
7"Jan","Feb","Mar","Apr","Maj","Jun","Jul","Aug","Sep","Okt","Nov","Dec");
8
9// Create datapoints where every point
10$steps=100;
11for($i=0; $i<$steps; ++$i) {
12        $datay[$i]=log(pow($i,$i/10)+1)*sin($i/15)+35;
13        $databarx[]=sprintf("198%d %s",floor($i/12),$month[$i%12]);
14       
15        // Simulate an accumulated value for every 5:th data point
16        if( $i % 6 == 0 ) {
17                $databary[]=abs(25*sin($i)+5);
18        }
19        else {
20                $databary[]=0;
21        }
22       
23}
24
25
26// New graph with a background image and drop shadow
27$graph = new Graph(450,300);
28$graph->SetBackgroundImage("tiger_bkg.png",BGIMG_FILLFRAME);
29$graph->SetShadow();
30
31// Use an integer X-scale
32$graph->SetScale("textlin");
33
34// Set title and subtitle
35$graph->title->Set("Combined bar and line plot");
36$graph->subtitle->Set("100 data points, X-Scale: 'text'");
37
38// Use built in font
39$graph->title->SetFont(FF_FONT1,FS_BOLD);
40
41// Make the margin around the plot a little bit bigger
42// then default
43$graph->img->SetMargin(40,140,40,80);   
44
45// Slightly adjust the legend from it's default position in the
46// top right corner to middle right side
47$graph->legend->Pos(0.05,0.5,"right","center");
48
49// Display every 10:th datalabel
50$graph->xaxis->SetTextTickInterval(6);
51$graph->xaxis->SetTextLabelInterval(2);
52$graph->xaxis->SetTickLabels($databarx);
53$graph->xaxis->SetLabelAngle(90);
54
55// Create a red line plot
56$p1 = new LinePlot($datay);
57$p1->SetColor("red");
58$p1->SetLegend("Pressure");
59
60// Create the bar plot
61$b1 = new BarPlot($databary);
62$b1->SetLegend("Temperature");
63$b1->SetAbsWidth(6);
64$b1->SetShadow();
65
66// The order the plots are added determines who's ontop
67$graph->Add($p1);
68$graph->Add($b1);
69
70// Finally output the  image
71$graph->Stroke();
72
73?>
74
75
Note: See TracBrowser for help on using the repository browser.