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