source: trunk/xgraph/jpgraph/Examples/horizbarex3.php

Last change on this file was 42, checked in by marrucho, 10 years ago
File size: 2.6 KB
Line 
1<?php // content="text/plain; charset=utf-8"
2require_once ('jpgraph/jpgraph.php');
3require_once ('jpgraph/jpgraph_bar.php');
4
5$datay=array(2,3,-5,8,12,6,3);
6$datax=array("Jan","Feb","Mar","Apr","May","Jun","Jul");
7
8// Size of graph
9$width=400; 
10$height=500;
11
12// Set the basic parameters of the graph
13$graph = new Graph($width,$height,'auto');
14$graph->SetScale("textlin");
15
16$top = 50;
17$bottom = 80;
18$left = 50;
19$right = 20;
20$graph->Set90AndMargin($left,$right,$top,$bottom);
21
22$graph->xaxis->SetPos('min');
23
24// Nice shadow
25$graph->SetShadow();
26
27// Setup title
28$graph->title->Set("Horizontal bar graph ex 3");
29$graph->title->SetFont(FF_VERDANA,FS_BOLD,14);
30$graph->subtitle->Set("(Axis at bottom)");
31
32// Setup X-axis
33$graph->xaxis->SetTickLabels($datax);
34$graph->xaxis->SetFont(FF_FONT2,FS_BOLD,12);
35
36// Some extra margin looks nicer
37$graph->xaxis->SetLabelMargin(5);
38
39// Label align for X-axis
40$graph->xaxis->SetLabelAlign('right','center');
41
42// Add some grace to y-axis so the bars doesn't go
43// all the way to the end of the plot area
44$graph->yaxis->scale->SetGrace(20);
45
46// Setup the Y-axis to be displayed in the bottom of the
47// graph. We also finetune the exact layout of the title,
48// ticks and labels to make them look nice.
49$graph->yaxis->SetPos('max');
50
51// First make the labels look right
52$graph->yaxis->SetLabelAlign('center','top');
53$graph->yaxis->SetLabelFormat('%d');
54$graph->yaxis->SetLabelSide(SIDE_RIGHT);
55
56// The fix the tick marks
57$graph->yaxis->SetTickSide(SIDE_LEFT);
58
59// Finally setup the title
60$graph->yaxis->SetTitleSide(SIDE_RIGHT);
61$graph->yaxis->SetTitleMargin(35);
62
63// To align the title to the right use :
64$graph->yaxis->SetTitle('Turnaround 2002','high');
65$graph->yaxis->title->Align('right');
66
67// To center the title use :
68//$graph->yaxis->SetTitle('Turnaround 2002','center');
69//$graph->yaxis->title->Align('center');
70
71$graph->yaxis->title->SetFont(FF_ARIAL,FS_BOLD,12);
72$graph->yaxis->title->SetAngle(0);
73
74$graph->yaxis->SetFont(FF_FONT2,FS_NORMAL);
75// If you want the labels at an angle other than 0 or 90
76// you need to use TTF fonts
77//$graph->yaxis->SetLabelAngle(0);
78
79// Now create a bar pot
80$bplot = new BarPlot($datay);
81$bplot->SetFillColor("orange");
82$bplot->SetShadow();
83
84//You can change the width of the bars if you like
85//$bplot->SetWidth(0.5);
86
87// We want to display the value of each bar at the top
88$bplot->value->Show();
89$bplot->value->SetFont(FF_ARIAL,FS_BOLD,12);
90$bplot->value->SetAlign('left','center');
91$bplot->value->SetColor("black","darkred");
92$bplot->value->SetFormat('%.1f mkr');
93
94// Add the bar to the graph
95$graph->Add($bplot);
96
97
98$graph->Stroke();
99?>
Note: See TracBrowser for help on using the repository browser.