1 | <?php // content="text/plain; charset=utf-8" |
---|
2 | // $Id: piec_csimex1.php,v 1.1.2.1 2003/10/09 21:05:39 aditus Exp $ |
---|
3 | // Example of pie with center circle |
---|
4 | require_once ('jpgraph/jpgraph.php'); |
---|
5 | require_once ('jpgraph/jpgraph_pie.php'); |
---|
6 | |
---|
7 | // Some data |
---|
8 | $data = array(50,28,25,27,31,20); |
---|
9 | |
---|
10 | // A new pie graph |
---|
11 | $graph = new PieGraph(400,400); |
---|
12 | |
---|
13 | // If you don't want any border just uncomment this line |
---|
14 | // $graph->SetFrame(false); |
---|
15 | |
---|
16 | // Uncomment this line to add a drop shadow to the border |
---|
17 | // $graph->SetShadow(); |
---|
18 | |
---|
19 | // Setup title |
---|
20 | $graph->title->Set("CSIM Center Pie plot ex 1"); |
---|
21 | $graph->title->SetFont(FF_ARIAL,FS_BOLD,18); |
---|
22 | $graph->title->SetMargin(8); // Add a little bit more margin from the top |
---|
23 | |
---|
24 | // Create the pie plot |
---|
25 | $p1 = new PiePlotC($data); |
---|
26 | |
---|
27 | // Set the radius of pie (as fraction of image size) |
---|
28 | $p1->SetSize(0.32); |
---|
29 | |
---|
30 | // Move the center of the pie slightly to the top of the image |
---|
31 | $p1->SetCenter(0.5,0.45); |
---|
32 | |
---|
33 | // Label font and color setup |
---|
34 | $p1->value->SetFont(FF_ARIAL,FS_BOLD,12); |
---|
35 | $p1->value->SetColor('white'); |
---|
36 | |
---|
37 | // Setup the title on the center circle |
---|
38 | $p1->midtitle->Set("Test mid\nRow 1\nRow 2"); |
---|
39 | $p1->midtitle->SetFont(FF_ARIAL,FS_NORMAL,14); |
---|
40 | |
---|
41 | // Set color for mid circle |
---|
42 | $p1->SetMidColor('yellow'); |
---|
43 | |
---|
44 | // Use percentage values in the legends values (This is also the default) |
---|
45 | $p1->SetLabelType(PIE_VALUE_PER); |
---|
46 | |
---|
47 | // The label array values may have printf() formatting in them. The argument to the |
---|
48 | // form,at string will be the value of the slice (either the percetage or absolute |
---|
49 | // depending on what was specified in the SetLabelType() above. |
---|
50 | $lbl = array("adam\n%.1f%%","bertil\n%.1f%%","johan\n%.1f%%", |
---|
51 | "peter\n%.1f%%","daniel\n%.1f%%","erik\n%.1f%%"); |
---|
52 | $p1->SetLabels($lbl); |
---|
53 | |
---|
54 | // Uncomment this line to remove the borders around the slices |
---|
55 | // $p1->ShowBorder(false); |
---|
56 | |
---|
57 | // Add drop shadow to slices |
---|
58 | $p1->SetShadow(); |
---|
59 | |
---|
60 | // Explode all slices 15 pixels |
---|
61 | $p1->ExplodeAll(15); |
---|
62 | |
---|
63 | // Setup the CSIM targets |
---|
64 | $targ=array("piec_csimex1.php#1","piec_csimex1.php#2","piec_csimex1.php#3", |
---|
65 | "piec_csimex1.php#4","piec_csimex1.php#5","piec_csimex1.php#6"); |
---|
66 | $alts=array("val=%d","val=%d","val=%d","val=%d","val=%d","val=%d"); |
---|
67 | $p1->SetCSIMTargets($targ,$alts); |
---|
68 | $p1->SetMidCSIM("piec_csimex1.php#7","Center"); |
---|
69 | |
---|
70 | |
---|
71 | // Setup a small help text in the image |
---|
72 | $txt = new Text("Note: This is an example of image map. Hold\nyour mouse over the slices to see the values.\nThe URL just points back to this page"); |
---|
73 | $txt->SetFont(FF_FONT1,FS_BOLD); |
---|
74 | $txt->SetPos(0.5,0.97,'center','bottom'); |
---|
75 | $txt->SetBox('yellow','black'); |
---|
76 | $txt->SetShadow(); |
---|
77 | $graph->AddText($txt); |
---|
78 | |
---|
79 | // Add plot to pie graph |
---|
80 | $graph->Add($p1); |
---|
81 | |
---|
82 | // .. and send the image on it's marry way to the browser |
---|
83 | $graph->StrokeCSIM(); |
---|
84 | |
---|
85 | ?> |
---|
86 | |
---|
87 | |
---|