ILIAS  Release_4_1_x_branch Revision 61804
 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  /* #8163
54  if (strlen($Titel) > 40)
55  {
56  $this->graph->SetFont("title", "benjamingothic.ttf", 6);
57  }
58  */
59  if (strlen($Titel) > 80)
60  {
61  $Titel = substr($Titel, 0, 80) . "...";
62  }
63  $this->graph->SetTitle($Titel);
64  $this->graph->SetXTitle($XLabel);
65  $this->graph->SetYTitle($YLabel);
66  $this->graph->SetXDataLabelPos("plotdown");
67  $this->makeDataForOneQuestion($DataArray, $GraphTyp);
68  $max = 0;
69  foreach ($this->graphData as $value)
70  {
71  if ($value[1] > $max) $max = $value[1];
72  }
73  $this->graph->SetYTickIncrement(ceil($max / 4));
74  $this->graph->SetDataValues($this->graphData);
75  $this->graph->SetPlotAreaWorld(NULL, 0, NULL, NULL);
76  $this->draw();
77  }
78 
79  function makeDataForOneQuestion($Data, $GraphTyp)
80  {
81  foreach ($Data as $value)
82  {
83  if (array_key_exists("title", $value))
84  {
85  switch ($GraphTyp)
86  {
87  case "pie":
88  array_push($this->graphData, array($value["title"], $value["selected"], ""));
89  break;
90  default:
91  array_push($this->graphData, array($value["title"], $value["selected"]));
92  break;
93  }
94  }
95  else
96  {
97  array_push($this->graphData, array($value["value"], $value["selected"]));
98  }
99  }
100  }
101 
102  function draw()
103  {
104  $this->graph->DrawGraph();
105  $this->graph->PrintImage();
106  }
107 }
108 
109 ?>