source: trunk/xgraph/jpgraph/Examples/csim_in_html_graph_ex2.php

Last change on this file was 42, checked in by marrucho, 10 years ago
File size: 2.1 KB
Line 
1<?php // content="text/plain; charset=utf-8"
2// Example of pie with center circle
3require_once ('jpgraph/jpgraph.php');
4require_once ('jpgraph/jpgraph_pie.php');
5
6// Some data
7$data = array(50,28,25,27,31,20);
8
9// A new pie graph
10$piegraph = new PieGraph(400,320);
11
12$n = count($data) ; // Number of slices
13
14// No border around graph
15$piegraph->SetFrame(false);
16
17// Setup title
18$piegraph->title->Set("CSIM Center Pie plot");
19$piegraph->title->SetFont(FF_ARIAL,FS_BOLD,18);
20$piegraph->title->SetMargin(8); // Add a little bit more margin from the top
21
22// Create the pie plot
23$p1 = new PiePlotC($data);
24
25// Set the radius of pie (as fraction of image size)
26$p1->SetSize(0.32);
27
28// Label font and color setup
29$p1->value->SetFont(FF_ARIAL,FS_BOLD,11);
30$p1->value->SetColor('white');
31
32// Setup the title on the center circle
33$p1->midtitle->Set("Distribution\n2008 H1");
34$p1->midtitle->SetFont(FF_ARIAL,FS_NORMAL,12);
35
36// Set color for mid circle
37$p1->SetMidColor('yellow');
38
39// Use percentage values in the legends values (This is also the default)
40$p1->SetLabelType(PIE_VALUE_PER);
41
42// The label array values may have printf() formatting in them. The argument to the
43// form,at string will be the value of the slice (either the percetage or absolute
44// depending on what was specified in the SetLabelType() above.
45$lbl = array("Jan\n%.1f%%","Feb\n%.1f%%","March\n%.1f%%",
46             "Apr\n%.1f%%","May\n%.1f%%","Jun\n%.1f%%");
47$p1->SetLabels($lbl);
48
49// Add drop shadow to slices
50$p1->SetShadow();
51
52// Explode all slices 15 pixels
53$p1->ExplodeAll(15);
54
55// Setup the CSIM targets
56global $_wrapperfilename;
57$targ = array(); $alt = array(); $wtarg = array();
58for( $i=0; $i <= $n; ++$i ) {
59    $urlarg = 'pie_clickedon='.($i+1);
60    $targ[] = $_wrapperfilename.'?'.$urlarg;
61    $alt[] = 'val=%d';
62    $wtarg[] = '';
63}
64$p1->SetCSIMTargets($targ,$alt,$wtarg);
65$p1->SetMidCSIM($targ[0],$alt[0],$wtarg[0]);
66
67// Add plot to pie graph
68$piegraph->Add($p1);
69
70// Send back the image when we are called from within the <img> tag
71$piegraph->StrokeCSIMImage();
72
73?>
74
75
Note: See TracBrowser for help on using the repository browser.