ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
custom.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
26 
33 function custom()
34 {
35  //Loading factories
36  global $DIC;
37  $f = $DIC->ui()->factory();
38  $df = new \ILIAS\Data\Factory();
39  $renderer = $DIC->ui()->renderer();
40 
41  //Generating Dimensions
42  $c_dimension = $df->dimension()->cardinal(["", "low", "medium", "high"]);
43  $r_dimension = $df->dimension()->range($c_dimension);
44 
45  //Generating Dataset with points and tooltips
46  $dataset = $df->dataset([
47  "Target" => $r_dimension,
48  "Dataset 1" => $c_dimension,
49  "Dataset 2" => $c_dimension,
50  "Dataset 3" => $c_dimension,
51  ]);
52 
53  $dataset = $dataset->withPoint(
54  "Item 1",
55  [
56  "Target" => [0.99, 1.01],
57  "Dataset 1" => 1,
58  "Dataset 2" => 0,
59  "Dataset 3" => 1
60  ]
61  );
62  $dataset = $dataset->withPoint(
63  "Item 2",
64  [
65  "Target" => [2.99, 3.01],
66  "Dataset 1" => 1,
67  "Dataset 2" => 3,
68  "Dataset 3" => 1.5
69  ]
70  );
71  $dataset = $dataset->withPoint(
72  "Item 3",
73  [
74  "Target" => [2.99, 3.01],
75  "Dataset 1" => 0,
76  "Dataset 2" => 1,
77  "Dataset 3" => 0.75
78  ]
79  );
80  $dataset = $dataset->withPoint(
81  "Item 4",
82  [
83  "Target" => [1.99, 2.01],
84  "Dataset 1" => 2,
85  "Dataset 2" => null,
86  "Dataset 3" => 2.5
87  ]
88  );
89  $dataset = $dataset->withPoint(
90  "Item 5",
91  [
92  "Target" => [2.99, 3.01],
93  "Dataset 1" => 1,
94  "Dataset 2" => 1,
95  "Dataset 3" => 1.8
96  ]
97  );
98  $dataset = $dataset->withPoint(
99  "Item 6",
100  [
101  "Target" => [0, 0.01],
102  "Dataset 1" => 0,
103  "Dataset 2" => 3,
104  "Dataset 3" => 0.2
105  ]
106  );
107 
108  $dataset = $dataset->withAlternativeInformation(
109  "Item 1",
110  [
111  "Target" => "low",
112  "Dataset 1" => null,
113  "Dataset 2" => null,
114  "Dataset 3" => "Custom 1"
115  ]
116  );
117  $dataset = $dataset->withAlternativeInformation(
118  "Item 2",
119  [
120  "Target" => "high",
121  "Dataset 1" => null,
122  "Dataset 2" => null,
123  "Dataset 3" => "Custom 2"
124  ]
125  );
126  $dataset = $dataset->withAlternativeInformation(
127  "Item 3",
128  [
129  "Target" => "high",
130  "Dataset 1" => null,
131  "Dataset 2" => null,
132  "Dataset 3" => "Custom 3"
133  ]
134  );
135  $dataset = $dataset->withAlternativeInformation(
136  "Item 4",
137  [
138  "Target" => "medium",
139  "Dataset 1" => null,
140  "Dataset 2" => null,
141  "Dataset 3" => "Custom 4"
142  ]
143  );
144  $dataset = $dataset->withAlternativeInformation(
145  "Item 5",
146  [
147  "Target" => "high",
148  "Dataset 1" => null,
149  "Dataset 2" => null,
150  "Dataset 3" => "Custom 5"
151  ]
152  );
153  $dataset = $dataset->withAlternativeInformation(
154  "Item 6",
155  [
156  "Target" => "-",
157  "Dataset 1" => null,
158  "Dataset 2" => null,
159  "Dataset 3" => "Custom 6"
160  ]
161  );
162 
163  //Generating Bar Configurations
164  $b1 = new BarConfig();
165  $b1 = $b1->withRelativeWidth(1.1);
166  $b1 = $b1->withColor($df->color("#000000"));
167  $b2 = new BarConfig();
168  $b2 = $b2->withRelativeWidth(0.6);
169  $b2 = $b2->withColor($df->color("#12436D"));
170  $b3 = new BarConfig();
171  $b3 = $b3->withRelativeWidth(0.6);
172  $b3 = $b3->withColor($df->color("#28A197"));
173  $b4 = new BarConfig();
174  $b4 = $b4->withRelativeWidth(0.6);
175  $b4 = $b4->withColor($df->color("#801650"));
176 
177  $bars = [
178  "Target" => $b1,
179  "Dataset 1" => $b2,
180  "Dataset 2" => $b3,
181  "Dataset 3" => $b4
182  ];
183 
184  //Generating and rendering the horizontal chart
185  $bar_chart = $f->chart()->bar()->horizontal(
186  "A horizontal bar chart",
187  $dataset,
188  $bars
189  );
190  $bar_chart = $bar_chart->withTitleVisible(false);
191  $x_axis = new XAxis();
192  $x_axis = $x_axis->withMinValue(0);
193  $x_axis = $x_axis->withMaxValue(3);
194  $bar_chart = $bar_chart->withCustomXAxis($x_axis);
195 
196  // render
197  return $renderer->render($bar_chart);
198 }
$renderer
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:26
custom()
expected output: > ILIAS shows a base horizontal bar chart but customized with e.g.
Definition: custom.php:33