ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.SurveyChart.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
34 {
35  var $graph;
37 
38  function SurveyChart($GraphTyp,$XSize,$YSize,$Titel,$XLabel,$YLabel,$DataArray)
39  {
40  $this->graphData = array();
41  include_once ("./Modules/SurveyQuestionPool/phplot/phplot.php");
42  $this->graph = new PHPlot($XSize,$YSize);
43  switch ($GraphTyp)
44  {
45  case "pie":
46  $this->graph->SetDataType("text-data-single");
47  break;
48  default:
49  $this->graph->SetDataType("text-data");
50  break;
51  }
52  $this->graph->SetPlotType($GraphTyp);
53  if (strlen($Titel) > 40)
54  {
55  $this->graph->SetFont("title", "benjamingothic.ttf", 6);
56  }
57  if (strlen($Titel) > 80)
58  {
59  $Titel = substr($Titel, 0, 80) . "...";
60  }
61  $this->graph->SetTitle($Titel);
62  $this->graph->SetXTitle($XLabel);
63  $this->graph->SetYTitle($YLabel);
64  $this->graph->SetXDataLabelPos("plotdown");
65  $this->makeDataForOneQuestion($DataArray, $GraphTyp);
66  $max = 0;
67  foreach ($this->graphData as $value)
68  {
69  if ($value[1] > $max) $max = $value[1];
70  }
71  $this->graph->SetYTickIncrement(ceil($max / 4));
72  $this->graph->SetDataValues($this->graphData);
73  $this->graph->SetPlotAreaWorld(NULL, 0, NULL, NULL);
74  $this->draw();
75  }
76 
77  function makeDataForOneQuestion($Data, $GraphTyp)
78  {
79  foreach ($Data as $value)
80  {
81  if (array_key_exists("title", $value))
82  {
83  switch ($GraphTyp)
84  {
85  case "pie":
86  array_push($this->graphData, array($value["title"], $value["selected"], ""));
87  break;
88  default:
89  array_push($this->graphData, array($value["title"], $value["selected"]));
90  break;
91  }
92  }
93  else
94  {
95  array_push($this->graphData, array($value["value"], $value["selected"]));
96  }
97  }
98  }
99 
100  function draw()
101  {
102  $this->graph->DrawGraph();
103  $this->graph->PrintImage();
104  }
105 }
106 
107 ?>