ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
partly_stacked.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
11 
18 function partly_stacked()
19 {
20  //Loading factories
21  global $DIC;
22  $f = $DIC->ui()->factory();
23  $df = new \ILIAS\Data\Factory();
24  $renderer = $DIC->ui()->renderer();
25 
26  //Generating Dimensions
27  $c_dimension = $df->dimension()->cardinal();
28 
29  //Generating Dataset with points and tooltips
30  $dataset = $df->dataset([
31  "Dataset 1.1" => $c_dimension,
32  "Dataset 1.2" => $c_dimension,
33  "Dataset 2" => $c_dimension,
34  ], [
35  "Grouped Dataset 1" => $df->dimension()->group("Dataset 1.1", "Dataset 1.2")
36  ]);
37 
38  $dataset = $dataset->withPoint(
39  "Item 1",
40  [
41  "Dataset 1.1" => 8,
42  "Dataset 1.2" => 7,
43  "Dataset 2" => 10
44  ]
45  );
46  $dataset = $dataset->withPoint(
47  "Item 2",
48  [
49  "Dataset 1.1" => 2,
50  "Dataset 1.2" => 5,
51  "Dataset 2" => 3
52  ]
53  );
54  $dataset = $dataset->withPoint(
55  "Item 3",
56  [
57  "Dataset 1.1" => -4,
58  "Dataset 1.2" => 10,
59  "Dataset 2" => 6
60  ]
61  );
62 
63  //Generating Bar Configurations
64  $b1 = new BarConfig();
65  $b1 = $b1->withColor($df->color("#12436D"));
66  $b2 = new BarConfig();
67  $b2 = $b2->withColor($df->color("#28A197"));
68  $b3 = new BarConfig();
69  $b3 = $b3->withColor($df->color("#801650"));
70  $g1 = new GroupConfig();
71  $g1 = $g1->withStacked(true);
72 
73  $bars = [
74  "Dataset 1.1" => $b1,
75  "Dataset 1.2" => $b2,
76  "Dataset 2" => $b3
77  ];
78  $groups = [
79  "Grouped Dataset 1" => $g1
80  ];
81 
82  //Generating and rendering the vertical chart
83  $bar = $f->chart()->bar()->vertical(
84  "A vertical partly stacked bar chart",
85  $dataset,
86  $bars,
87  $groups
88  );
89 
90  // render
91  return $renderer->render($bar);
92 }
$renderer
partly_stacked()
expected output: > ILIAS shows a base column-chart but with stacked bars in different colors...
global $DIC
Definition: shib_login.php:25