1 | <?php // content="text/plain; charset=utf-8" |
---|
2 | require_once ('jpgraph/jpgraph.php'); |
---|
3 | require_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 | // Rotate graph 90 degrees and set margin |
---|
17 | $graph->Set90AndMargin(50,20,50,30); |
---|
18 | |
---|
19 | // Nice shadow |
---|
20 | $graph->SetShadow(); |
---|
21 | |
---|
22 | // Setup title |
---|
23 | $graph->title->Set('Horizontal bar graph ex 1'); |
---|
24 | $graph->title->SetFont(FF_VERDANA,FS_BOLD,14); |
---|
25 | |
---|
26 | // Setup X-axis |
---|
27 | $graph->xaxis->SetTickLabels($datax); |
---|
28 | $graph->xaxis->SetFont(FF_VERDANA,FS_NORMAL,12); |
---|
29 | |
---|
30 | // Some extra margin looks nicer |
---|
31 | $graph->xaxis->SetLabelMargin(10); |
---|
32 | |
---|
33 | // Label align for X-axis |
---|
34 | $graph->xaxis->SetLabelAlign('right','center'); |
---|
35 | |
---|
36 | // Add some grace to y-axis so the bars doesn't go |
---|
37 | // all the way to the end of the plot area |
---|
38 | $graph->yaxis->scale->SetGrace(20); |
---|
39 | |
---|
40 | // We don't want to display Y-axis |
---|
41 | $graph->yaxis->Hide(); |
---|
42 | |
---|
43 | // Now create a bar pot |
---|
44 | $bplot = new BarPlot($datay); |
---|
45 | $bplot->SetFillColor('orange'); |
---|
46 | $bplot->SetShadow(); |
---|
47 | |
---|
48 | //You can change the width of the bars if you like |
---|
49 | //$bplot->SetWidth(0.5); |
---|
50 | |
---|
51 | // We want to display the value of each bar at the top |
---|
52 | $bplot->value->Show(); |
---|
53 | $bplot->value->SetFont(FF_ARIAL,FS_BOLD,12); |
---|
54 | $bplot->value->SetAlign('left','center'); |
---|
55 | $bplot->value->SetColor('black','darkred'); |
---|
56 | $bplot->value->SetFormat('%.1f mkr'); |
---|
57 | |
---|
58 | // Add the bar to the graph |
---|
59 | $graph->Add($bplot); |
---|
60 | |
---|
61 | // .. and stroke the graph |
---|
62 | $graph->Stroke(); |
---|
63 | ?> |
---|