[42] | 1 | <?php // content="text/plain; charset=utf-8" |
---|
| 2 | // $Id: piecex2.php,v 1.3.2.1 2003/08/19 20:40:12 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,'auto'); |
---|
| 12 | |
---|
| 13 | // Don't display the border |
---|
| 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("PiePlotC"); |
---|
| 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 size of pie |
---|
| 28 | $p1->SetSize(0.35); |
---|
| 29 | |
---|
| 30 | // Label font and color setup |
---|
| 31 | $p1->value->SetFont(FF_ARIAL,FS_BOLD,12); |
---|
| 32 | $p1->value->SetColor('white'); |
---|
| 33 | |
---|
| 34 | $p1->value->Show(); |
---|
| 35 | |
---|
| 36 | // Setup the title on the center circle |
---|
| 37 | $p1->midtitle->Set("Test mid\nRow 1\nRow 2"); |
---|
| 38 | $p1->midtitle->SetFont(FF_ARIAL,FS_NORMAL,14); |
---|
| 39 | |
---|
| 40 | // Set color for mid circle |
---|
| 41 | $p1->SetMidColor('yellow'); |
---|
| 42 | |
---|
| 43 | // Use percentage values in the legends values (This is also the default) |
---|
| 44 | $p1->SetLabelType(PIE_VALUE_PER); |
---|
| 45 | |
---|
| 46 | // The label array values may have printf() formatting in them. The argument to the |
---|
| 47 | // form,at string will be the value of the slice (either the percetage or absolute |
---|
| 48 | // depending on what was specified in the SetLabelType() above. |
---|
| 49 | $lbl = array("adam\n%.1f%%","bertil\n%.1f%%","johan\n%.1f%%", |
---|
| 50 | "peter\n%.1f%%","daniel\n%.1f%%","erik\n%.1f%%"); |
---|
| 51 | $p1->SetLabels($lbl); |
---|
| 52 | |
---|
| 53 | // Uncomment this line to remove the borders around the slices |
---|
| 54 | // $p1->ShowBorder(false); |
---|
| 55 | |
---|
| 56 | // Add drop shadow to slices |
---|
| 57 | $p1->SetShadow(); |
---|
| 58 | |
---|
| 59 | // Explode all slices 15 pixels |
---|
| 60 | $p1->ExplodeAll(15); |
---|
| 61 | |
---|
| 62 | // Add plot to pie graph |
---|
| 63 | $graph->Add($p1); |
---|
| 64 | |
---|
| 65 | // .. and send the image on it's marry way to the browser |
---|
| 66 | $graph->Stroke(); |
---|
| 67 | |
---|
| 68 | ?> |
---|
| 69 | |
---|
| 70 | |
---|