| 1 |
lars |
1 |
<?php
|
|
|
2 |
// $Id: piebkgex1.php,v 1.3 2002/10/23 08:17:23 aditus Exp $
|
|
|
3 |
include ("../jpgraph.php");
|
|
|
4 |
include ("../jpgraph_pie.php");
|
|
|
5 |
include ("../jpgraph_pie3d.php");
|
|
|
6 |
|
|
|
7 |
// Some data
|
|
|
8 |
$data = array(
|
|
|
9 |
array(80,18,15,17),
|
|
|
10 |
array(35,28,6,34),
|
|
|
11 |
array(10,28,10,5),
|
|
|
12 |
array(22,22,10,17));
|
|
|
13 |
|
|
|
14 |
$piepos = array(0.2,0.4,0.65,0.28,0.25,0.75,0.8,0.75);
|
|
|
15 |
$titles = array('USA','Sweden','South America','Australia');
|
|
|
16 |
|
|
|
17 |
$n = count($piepos)/2;
|
|
|
18 |
|
|
|
19 |
// A new graph
|
|
|
20 |
$graph = new PieGraph(550,400,'auto');
|
|
|
21 |
|
|
|
22 |
// Specify margins since we put the image in the plot area
|
|
|
23 |
$graph->SetMargin(1,1,40,1);
|
|
|
24 |
$graph->SetMarginColor('navy');
|
|
|
25 |
$graph->SetShadow(false);
|
|
|
26 |
|
|
|
27 |
// Setup background
|
|
|
28 |
$graph->SetBackgroundImage('worldmap1.jpg',BGIMG_FILLPLOT);
|
|
|
29 |
|
|
|
30 |
// Setup title
|
|
|
31 |
$graph->title->Set("Pie plots with background image");
|
|
|
32 |
$graph->title->SetFont(FF_ARIAL,FS_BOLD,20);
|
|
|
33 |
$graph->title->SetColor('white');
|
|
|
34 |
|
|
|
35 |
$p = array();
|
|
|
36 |
// Create the plots
|
|
|
37 |
for( $i=0; $i < $n; ++$i ) {
|
|
|
38 |
$d = "data$i";
|
|
|
39 |
$p[] = new PiePlot3D($data[$i]);
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
// Position the four pies
|
|
|
43 |
for( $i=0; $i < $n; ++$i ) {
|
|
|
44 |
$p[$i]->SetCenter($piepos[2*$i],$piepos[2*$i+1]);
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
// Set the titles
|
|
|
48 |
for( $i=0; $i < $n; ++$i ) {
|
|
|
49 |
$p[$i]->title->Set($titles[$i]);
|
|
|
50 |
$p[$i]->title->SetColor('white');
|
|
|
51 |
$p[$i]->title->SetFont(FF_ARIAL,FS_BOLD,12);
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
// Label font and color setup
|
|
|
55 |
for( $i=0; $i < $n; ++$i ) {
|
|
|
56 |
$p[$i]->value->SetFont(FF_ARIAL,FS_BOLD);
|
|
|
57 |
$p[$i]->value->SetColor('white');
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
// Show the percetages for each slice
|
|
|
61 |
for( $i=0; $i < $n; ++$i ) {
|
|
|
62 |
$p[$i]->value->Show();
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
// Label format
|
|
|
66 |
for( $i=0; $i < $n; ++$i ) {
|
|
|
67 |
$p[$i]->value->SetFormat("%01.1f%%");
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
// Size of pie in fraction of the width of the graph
|
|
|
71 |
for( $i=0; $i < $n; ++$i ) {
|
|
|
72 |
$p[$i]->SetSize(0.15);
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
// Format the border around each slice
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
for( $i=0; $i < $n; ++$i ) {
|
|
|
79 |
$p[$i]->SetEdge(false);
|
|
|
80 |
$p[$i]->ExplodeSlice(1);
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
// Use one legend for the whole graph
|
|
|
84 |
$p[0]->SetLegends(array("May","June","July","Aug"));
|
|
|
85 |
$graph->legend->Pos(0.05,0.35);
|
|
|
86 |
$graph->legend->SetShadow(false);
|
|
|
87 |
|
|
|
88 |
for( $i=0; $i < $n; ++$i ) {
|
|
|
89 |
$graph->Add($p[$i]);
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
$graph->Stroke();
|
|
|
93 |
?>
|
|
|
94 |
|
|
|
95 |
|