3 * FusionForge Survey HTML Facility
4 * General Graph showing module for Survey
6 * Copyright 2010 (c) FusionForge Team
7 * http://fusionforge.org/
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * This script produces PNG image which shows graph of SCM metrics
31 * @ legend[] - array of legends
32 * @ value[] - array of values
33 * @ type - grap type. We support pie and vertical bar graph (pie, vbar)
38 require_once('../../env.inc.php');
39 require_once $gfcommon.'include/pre.php';
41 // Check if we have jpgraph
42 if (!file_exists(forge_get_config('jpgraph_path').'/jpgraph.php')) {
43 //# TODO: Need to show the message as a image file
44 exit_error(_('Package JPGraph not installed'),'surveys');
47 // Read jPGraph libraries.
48 require_once forge_get_config('jpgraph_path').'/jpgraph.php';
49 require_once forge_get_config('jpgraph_path').'/jpgraph_line.php';
50 require_once forge_get_config('jpgraph_path').'/jpgraph_bar.php';
51 require_once forge_get_config('jpgraph_path').'/jpgraph_pie.php';
52 require_once forge_get_config('jpgraph_path').'/jpgraph_pie3d.php';
54 $type = getStringFromRequest('type');
55 $legend = getStringFromRequest('legend');
56 $value = getStringFromRequest('value');
59 ShowPie($legend, $value);
61 ShowHBar($legend, $value);
67 function ShowPie(&$legend, &$value) {
69 $graph = new PieGraph(330,200,"auto");
70 $graph->SetFrame(false);
71 //$graph->title->Set("A simple 3D Pie plot");
72 //$graph->title->SetFont(FF_FONT1,FS_BOLD);
74 $p1 = new PiePlot3D($value);
77 $p1->SetLegends($legend);
78 $graph->legend->SetPos(0.01,0.01,'right','top');
86 * Show Horizontal Bar graph
88 function ShowHBar(&$legend, &$value) {
90 $height=50+count($value)*18;
93 // Set the basic parameters of the graph
94 $graph = new Graph($width,$height,'auto');
96 $graph->SetScale("textlin");
101 $graph->Set90AndMargin($left,$right,$top,$bottom);
102 $graph->xaxis->SetTickLabels($legend);
103 $graph->SetFrame(false);
105 // Label align for X-axis
106 $graph->xaxis->SetLabelAlign('right','center','right');
108 // Label align for Y-axis
109 $graph->yaxis->SetLabelAlign('center','bottom');
112 $bplot = new BarPlot($value);
113 $bplot->SetFillColor("orange");
114 $bplot->SetWidth(0.5);
115 // We want to display the value of each bar at the top
116 $graph->yaxis->scale->SetGrace(10);
117 $graph->yaxis->SetLabelAlign('center','bottom');
118 $graph->yaxis->SetLabelFormat('%d');
120 $bplot->value->Show();
121 $bplot->value->SetFormat('%.d votes');
122 // Setup color for gradient fill style
123 $bplot->SetFillGradient("navy","lightsteelblue",GRAD_MIDVER);