ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
partly_stacked.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
35{
36 //Loading factories
37 global $DIC;
38 $f = $DIC->ui()->factory();
39 $df = new \ILIAS\Data\Factory();
40 $renderer = $DIC->ui()->renderer();
41
42 //Generating Dimensions
43 $c_dimension = $df->dimension()->cardinal();
44
45 //Generating Dataset with points and tooltips
46 $dataset = $df->dataset([
47 "Dataset 1.1" => $c_dimension,
48 "Dataset 1.2" => $c_dimension,
49 "Dataset 2" => $c_dimension,
50 ], [
51 "Grouped Dataset 1" => $df->dimension()->group("Dataset 1.1", "Dataset 1.2")
52 ]);
53
54 $dataset = $dataset->withPoint(
55 "Item 1",
56 [
57 "Dataset 1.1" => 8,
58 "Dataset 1.2" => 7,
59 "Dataset 2" => 10
60 ]
61 );
62 $dataset = $dataset->withPoint(
63 "Item 2",
64 [
65 "Dataset 1.1" => 2,
66 "Dataset 1.2" => 5,
67 "Dataset 2" => 3
68 ]
69 );
70 $dataset = $dataset->withPoint(
71 "Item 3",
72 [
73 "Dataset 1.1" => -4,
74 "Dataset 1.2" => 10,
75 "Dataset 2" => 6
76 ]
77 );
78
79 //Generating Bar Configurations
80 $b1 = new BarConfig();
81 $b1 = $b1->withColor($df->color("#12436D"));
82 $b2 = new BarConfig();
83 $b2 = $b2->withColor($df->color("#28A197"));
84 $b3 = new BarConfig();
85 $b3 = $b3->withColor($df->color("#801650"));
86 $g1 = new GroupConfig();
87 $g1 = $g1->withStacked(true);
88
89 $bars = [
90 "Dataset 1.1" => $b1,
91 "Dataset 1.2" => $b2,
92 "Dataset 2" => $b3
93 ];
94 $groups = [
95 "Grouped Dataset 1" => $g1
96 ];
97
98 //Generating and rendering the vertical chart
99 $bar = $f->chart()->bar()->vertical(
100 "A vertical partly stacked bar chart",
101 $dataset,
102 $bars,
103 $groups
104 );
105
106 // render
107 return $renderer->render($bar);
108}
$renderer
global $DIC
Definition: shib_login.php:26