4 * General Graph showing module for Survey
6 * This script produces PNG image which shows graph of SCM metrics
13 * @ legend[] - array of legends
14 * @ value[] - array of values
15 * @ type - grap type. We support pie and vertical bar graph (pie, vbar)
20 require_once('../../env.inc.php');
21 require_once('pre.php');
23 // Check if we have jpgraph
24 if (!file_exists($sys_path_to_jpgraph.'/jpgraph.php')) {
25 //# TODO: Need to show the message as a image file
26 exit_error('Error', 'Package JPGraph not installed');
29 // Read jPGraph libraries. Make sure the $sys_path_to_jpgraph is correct in local.inc
30 require_once($sys_path_to_jpgraph.'/jpgraph.php');
31 require_once($sys_path_to_jpgraph.'/jpgraph_line.php');
32 require_once($sys_path_to_jpgraph.'/jpgraph_bar.php');
33 require_once($sys_path_to_jpgraph.'/jpgraph_pie.php');
34 require_once($sys_path_to_jpgraph.'/jpgraph_pie3d.php');
36 $type = getStringFromRequest('type');
37 $legend = getStringFromRequest('legend');
38 $value = getStringFromRequest('value');
41 ShowPie($legend, $value);
43 ShowHBar($legend, $value);
49 function ShowPie(&$legend, &$value) {
51 $graph = new PieGraph(330,200,"auto");
52 $graph->SetFrame(false);
53 //$graph->title->Set("A simple 3D Pie plot");
54 //$graph->title->SetFont(FF_FONT1,FS_BOLD);
56 $p1 = new PiePlot3D($value);
59 $p1->SetLegends($legend);
60 $graph->legend->SetPos(0.01,0.01,'right','top');
68 * Show Horizontal Bar graph
70 function ShowHBar(&$legend, &$value) {
72 $height=50+count($value)*18;
75 // Set the basic parameters of the graph
76 $graph = new Graph($width,$height,'auto');
78 $graph->SetScale("textlin");
83 $graph->Set90AndMargin($left,$right,$top,$bottom);
84 $graph->xaxis->SetTickLabels($legend);
85 $graph->SetFrame(false);
87 // Label align for X-axis
88 $graph->xaxis->SetLabelAlign('right','center','right');
90 // Label align for Y-axis
91 $graph->yaxis->SetLabelAlign('center','bottom');
94 $bplot = new BarPlot($value);
95 $bplot->SetFillColor("orange");
96 $bplot->SetWidth(0.5);
97 // We want to display the value of each bar at the top
98 $graph->yaxis->scale->SetGrace(10);
99 $graph->yaxis->SetLabelAlign('center','bottom');
100 $graph->yaxis->SetLabelFormat('%d');
102 $bplot->value->Show();
103 $bplot->value->SetFormat('%.d votes');
104 // Setup color for gradient fill style
105 $bplot->SetFillGradient("navy","lightsteelblue",GRAD_MIDVER);