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