30 protected string $id =
"";
44 $this->tpl =
$DIC[
"tpl"];
46 $this->data = array();
83 if (
sizeof($this->data)) {
92 public function setSize(
string $a_x,
string $a_y): void
105 if ($this->isValidDataType($a_series)) {
106 if ($a_idx ===
null) {
109 $this->data[$a_idx] = $a_series;
117 $this->legend = $a_legend;
122 foreach ($a_values as $color) {
123 if (self::isValidColor($color)) {
124 $this->colors[] = $color;
131 return $this->colors;
139 if (preg_match(
"/^#[0-9a-f]{3}$/i", $a_value, $match)) {
141 } elseif (preg_match(
"/^#[0-9a-f]{6}$/i", $a_value, $match)) {
154 if (self::isValidColor($a_value)) {
155 if (strlen($a_value) == 4) {
156 return "rgba(" . hexdec($a_value[1] . $a_value[1]) .
", " .
157 hexdec($a_value[2] . $a_value[2]) .
", " .
158 hexdec($a_value[3] . $a_value[3]) .
", " . $a_opacity .
")";
160 return "rgba(" . hexdec($a_value[1] . $a_value[2]) .
", " .
161 hexdec($a_value[3] . $a_value[4]) .
", " .
162 hexdec($a_value[5] . $a_value[6]) .
", " . $a_opacity .
")";
170 $this->shadow = $a_value;
175 return $this->shadow;
184 $this->auto_resize = $a_value;
201 $tpl->addJavaScript(
"assets/js/excanvas.min.js");
202 $tpl->addJavaScript(
"assets/js/jquery.flot.min.js");
204 if ($this->auto_resize) {
206 $tpl->addJavaScript(
"assets/js/jquery.flot.resize.min.js");
210 $tpl->addJavaScript(
"assets/js/jquery.flot.stack.min.js");
213 $this->addCustomJS();
235 if (!$this->isValid()) {
241 $chart =
new ilTemplate(
"tpl.grid.html",
true,
true,
"components/ILIAS/Chart");
242 $chart->setVariable(
"ID", $this->
id);
245 if (is_numeric($this->width)) {
246 $chart->setVariable(
"WIDTH",
"width:" . $this->width .
"px;");
248 $chart->setVariable(
"WIDTH",
"width:" . $this->width .
";");
252 if (is_numeric($this->height)) {
253 $chart->setVariable(
"HEIGHT",
"height:" . $this->height .
"px;");
255 $chart->setVariable(
"HEIGHT",
"height:" . $this->height .
";");
262 $json_series = array();
263 foreach ($this->data as $series) {
264 $series->parseData($json_series);
266 $series_str = json_encode($json_series);
271 $json_options =
new stdClass();
272 $json_options->series =
new stdClass();
273 $json_options->series->shadowSize = $this->getShadow();
274 $json_options->series->lines =
new stdClass();
275 $json_options->series->lines->show =
false;
276 $json_options->series->stack = $this->stacked;
278 foreach ($this->data as $series) {
279 $series->parseGlobalOptions($json_options, $this);
282 $this->parseGlobalOptions($json_options);
284 $colors = $this->getColors();
286 $json_options->colors = array();
287 foreach ($colors as $color) {
288 $json_options->colors[] = self::renderColor($color);
293 $json_options->legend =
new stdClass();
294 if (!$this->legend) {
295 $json_options->legend->show =
false;
297 $this->legend->parseOptions($json_options->legend);
300 $options = json_encode($json_options);
302 $this->tpl->addOnLoadCode(
'$.plot($("#ilChart' . $this->
id .
'"), ' . $series_str .
', ' . $options .
');');
304 $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.
getDataInstance(?int $a_type=null)
Get data series instance.
setAutoResize(bool $a_value)
Toggle auto-resizing on window resize/redraw.
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)
Base class for ILIAS Exception handling.
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('../ilias.ini.php'))