27 protected string $id =
"";
41 $this->tpl =
$DIC[
"tpl"];
43 $this->data = array();
80 if (
sizeof($this->data)) {
89 public function setSize(
string $a_x,
string $a_y): void
102 if ($this->isValidDataType($a_series)) {
103 if ($a_idx ===
null) {
106 $this->data[$a_idx] = $a_series;
114 $this->legend = $a_legend;
119 foreach ($a_values as $color) {
120 if (self::isValidColor($color)) {
121 $this->colors[] = $color;
128 return $this->colors;
136 if (preg_match(
"/^#[0-9a-f]{3}$/i", $a_value, $match)) {
138 } elseif (preg_match(
"/^#[0-9a-f]{6}$/i", $a_value, $match)) {
151 if (self::isValidColor($a_value)) {
152 if (strlen($a_value) == 4) {
153 return "rgba(" . hexdec($a_value[1] . $a_value[1]) .
", " .
154 hexdec($a_value[2] . $a_value[2]) .
", " .
155 hexdec($a_value[3] . $a_value[3]) .
", " . $a_opacity .
")";
157 return "rgba(" . hexdec($a_value[1] . $a_value[2]) .
", " .
158 hexdec($a_value[3] . $a_value[4]) .
", " .
159 hexdec($a_value[5] . $a_value[6]) .
", " . $a_opacity .
")";
167 $this->shadow = $a_value;
172 return $this->shadow;
181 $this->auto_resize = $a_value;
186 $this->stacked = $a_value;
198 $tpl->addJavaScript(
"Services/Chart/js/flot/excanvas.min.js");
199 $tpl->addJavaScript(
"Services/Chart/js/flot/jquery.flot.min.js");
201 if ($this->auto_resize) {
203 $tpl->addJavaScript(
"Services/Chart/js/flot/jquery.flot.resize.min.js");
206 if ($this->stacked) {
207 $tpl->addJavaScript(
"Services/Chart/js/flot/jquery.flot.stack.min.js");
210 $this->addCustomJS();
232 if (!$this->isValid()) {
238 $chart =
new ilTemplate(
"tpl.grid.html",
true,
true,
"Services/Chart");
239 $chart->setVariable(
"ID", $this->
id);
242 if (is_numeric($this->width)) {
243 $chart->setVariable(
"WIDTH",
"width:" . $this->width .
"px;");
245 $chart->setVariable(
"WIDTH",
"width:" . $this->width .
";");
249 if (is_numeric($this->height)) {
250 $chart->setVariable(
"HEIGHT",
"height:" . $this->height .
"px;");
252 $chart->setVariable(
"HEIGHT",
"height:" . $this->height .
";");
259 $json_series = array();
260 foreach ($this->data as $series) {
261 $series->parseData($json_series);
263 $series_str = json_encode($json_series);
268 $json_options =
new stdClass();
269 $json_options->series =
new stdClass();
270 $json_options->series->shadowSize = $this->getShadow();
271 $json_options->series->lines =
new stdClass();
272 $json_options->series->lines->show =
false;
273 $json_options->series->stack = $this->stacked;
275 foreach ($this->data as $series) {
276 $series->parseGlobalOptions($json_options, $this);
279 $this->parseGlobalOptions($json_options);
281 $colors = $this->getColors();
283 $json_options->colors = array();
284 foreach ($colors as $color) {
285 $json_options->colors[] = self::renderColor($color);
290 $json_options->legend =
new stdClass();
291 if (!$this->legend) {
292 $json_options->legend->show =
false;
294 $this->legend->parseOptions($json_options->legend);
297 $options = json_encode($json_options);
299 $this->tpl->addOnLoadCode(
'$.plot($("#ilChart' . $this->
id .
'"), ' . $series_str .
', ' . $options .
');');
301 $ret = $chart->get();
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isValidDataType(ilChartData $a_series)
Validate data series.
__construct(string $a_id)
initJS()
Init JS script files.
static getInstanceByType(int $a_type, string $a_id)
setLegend(ilChartLegend $a_legend)
ilGlobalTemplateInterface $tpl
static renderColor(string $a_value, float $a_opacity=1)
Render html color code.
setAutoResize(bool $a_value)
Toggle auto-resizing on window resize/redraw.
getDataInstance(int $a_type=null)
Get data series instance.
setColors(array $a_values)
isValid()
Basic validation.
addData(ilChartData $a_series, ?int $a_idx=null)
Add data series.
static isValidColor(string $a_value)
Validate html color code.
parseGlobalOptions(stdClass $a_options)
Convert (global) properties to flot config.
setSize(string $a_x, string $a_y)
Set chart size.
addCustomJS()
Add type-specific JS script.
setStacked(bool $a_value)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl