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