ILIAS  release_8 Revision v8.24
custom.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
6
10
11function 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();
21
22 //Generating Dataset with points and tooltips
23 $dataset = $df->dataset([
24 "Dataset 1" => $c_dimension,
25 "Dataset 2" => $c_dimension,
26 "Dataset 3" => $c_dimension,
27 ]);
28
29 $dataset = $dataset->withPoint(
30 "Item 1",
31 [
32 "Dataset 1" => 75,
33 "Dataset 2" => 80,
34 "Dataset 3" => 100
35 ]
36 );
37 $dataset = $dataset->withPoint(
38 "Item 2",
39 [
40 "Dataset 1" => 45,
41 "Dataset 2" => 30,
42 "Dataset 3" => 90
43 ]
44 );
45 $dataset = $dataset->withPoint(
46 "Item 3",
47 [
48 "Dataset 1" => 50,
49 "Dataset 2" => 100,
50 "Dataset 3" => 65.5
51 ]
52 );
53
54 //Generating Bar Configurations
55 $b1 = new BarConfig();
56 $b1 = $b1->withColor($df->color("#d38000"));
57 $b2 = new BarConfig();
58 $b2 = $b2->withColor($df->color("#307C88"));
59 $b3 = new BarConfig();
60 $b3 = $b3->withColor($df->color("#557b2e"));
61
62 $bars = [
63 "Dataset 1" => $b1,
64 "Dataset 2" => $b2,
65 "Dataset 3" => $b3
66 ];
67
68 //Generating and rendering the vertical chart
69 $bar = $f->chart()->bar()->vertical(
70 "A vertical bar chart",
71 $dataset,
72 $bars
73 );
74 $bar = $bar->withTitleVisible(false);
75 $bar = $bar->withLegendPosition("left");
76 $y_axis = new YAxis();
77 $y_axis = $y_axis->withPosition("right");
78 $y_axis = $y_axis->withStepSize(10);
79 $y_axis = $y_axis->withBeginAtZero(false);
80 $bar = $bar->withCustomYAxis($y_axis);
81
82 // render
83 return $renderer->render($bar);
84}
global $DIC
Definition: feed.php:28