4 include_once
"Services/Chart/classes/class.ilChartData.php";
5 include_once
"Services/Chart/classes/class.ilChartLegend.php";
35 public function __construct($a_id, $a_width = 500, $a_height = 500, $a_renderer =
"flot")
38 $this->data = array();
41 $this->
setSize($a_width, $a_height);
55 $this->renderer = (string)$a_value;
77 $this->width = (int)$a_x;
78 $this->height = (int)$a_y;
94 $this->data[$a_idx] = $a_series;
105 $this->legend = $a_legend;
116 if(preg_match(
"/^#[0-9a-f]{3}$/i", $a_value, $match))
120 else if(preg_match(
"/^#[0-9a-f]{6}$/i", $a_value, $match))
135 if(self::isValidColor($a_value))
137 if(strlen($a_value) == 4)
139 return "\"rgba(".hexdec($a_value[1].$a_value[1]).
", ".
140 hexdec($a_value[2].$a_value[2]).
", ".
141 hexdec($a_value[3].$a_value[3]).
", ".$a_opacity.
")\"";
145 return "\"rgba(".hexdec($a_value[1].$a_value[2]).
", ".
146 hexdec($a_value[3].$a_value[4]).
", ".
147 hexdec($a_value[5].$a_value[6]).
", ".$a_opacity.
")\"";
159 $this->shadow = (int)$a_value;
179 foreach($a_values as $color)
181 if(self::isValidColor($color))
183 $this->colors[] = $color;
205 public function setTicks($a_x, $a_y, $a_labeled =
false)
207 $this->ticks = array(
"x" => $a_x,
"y" => $a_y,
"labeled" => (
bool)$a_labeled);
227 include_once
"Services/jQuery/classes/class.iljQueryUtil.php";
231 $tpl->addJavascript(
"Services/Chart/js/flot/excanvas.min.js");
232 $tpl->addJavascript(
"Services/Chart/js/flot/jquery.flot.min.js");
233 $tpl->addJavascript(
"Services/Chart/js/flot/jquery.flot.pie.js");
235 $chart =
new ilTemplate(
"tpl.grid.html",
true,
true,
"Services/Chart");
236 $chart->setVariable(
"ID", $this->
id);
237 $chart->setVariable(
"WIDTH", $this->width);
238 $chart->setVariable(
"HEIGHT", $this->height);
240 $last = array_keys($this->data);
241 $last = array_pop($last);
243 foreach($this->data as $idx => $series)
245 $chart->setCurrentBlock(
"series");
246 $chart->setVariable(
"SERIES_LABEL", str_replace(
"\"",
"\\\"", $series->getLabel()));
247 $chart->setVariable(
"SERIES_TYPE", $series->getType());
249 $type = $series->getType();
254 foreach($series->getData() as $point)
256 $points[] =
"[".$point[0].
",".$point[1].
"]";
258 $chart->setVariable(
"SERIES_DATA",
"[ ".implode(
",", $points).
" ]");
263 $chart->setVariable(
"SERIES_DATA", array_pop($series->getData()));
267 $chart->setVariable(
"SERIES_END",
",");
270 $options = array(
"show: ".($series->isHidden() ?
"false" :
"true"));
271 if($type !=
"points")
273 $width = $series->getLineWidth();
276 $options[] =
"lineWidth:".$width;
280 $bar_options = $series->getBarOptions();
281 if($bar_options[
"width"] !== null)
283 $options[] =
"barWidth:".str_replace(
",",
".", $bar_options[
"width"]);
284 $options[] =
"align: \"".$bar_options[
"align"].
"\"";
285 if($bar_options[
"horizontal"])
287 $options[] =
"horizontal: true";
291 else if($type ==
"lines")
293 if($series->getLineSteps())
295 $options[] =
"steps: true";
301 $radius = $series->getPointRadius();
304 $options[] =
"radius:".$radius;
307 $fill = $series->getFill();
310 $options[] =
"fill: ".$fill[
"fill"];
313 $options[] =
"fillColor: ".self::renderColor($fill[
"color"], $fill[
"fill"]);
316 $chart->setVariable(
"SERIES_OPTIONS", implode(
", ", $options));
318 $chart->parseCurrentBlock();
324 $chart->setVariable(
"SHADOW", (
int)$this->
getShadow());
325 $chart->setVariable(
"IS_PIE", ($has_pie ?
"true" :
"false"));
338 $chart->setVariable(
"COLORS", implode(
",", $tmp));
344 $chart->setVariable(
"LEGEND",
"show: false");
348 $margin = $this->legend->getMargin();
351 $legend[] =
"noColumns: ".$this->legend->getColumns();
352 $legend[] =
"position: \"".$this->legend->getPosition().
"\"";
353 $legend[] =
"margin: [".$margin[
"x"].
", ".$margin[
"y"].
"]";
354 $legend[] =
"backgroundColor: ".self::renderColor($this->legend->getBackground());
355 $legend[] =
"backgroundOpacity: ".str_replace(
",",
".",$this->legend->getOpacity());
356 $legend[] =
"labelBoxBorderColor: ".self::renderColor($this->legend->getLabelBorder());
358 $chart->setVariable(
"LEGEND", implode(
", ",
$legend));
366 foreach(
$ticks as $axis => $def)
370 $tmp[$axis] = $axis.
"axis: { ticks: ".$def.
" }";
372 else if(is_array($def))
375 foreach($def as $idx => $value)
379 $ttmp[] =
"[".$idx.
", \"".$value.
"\"]";
386 $tmp[$axis] = $axis.
"axis: { ticks: [".implode(
", ", $ttmp).
"] }";
392 if(!isset($tmp[
"x"]) && $this->integer_axis[
"x"])
394 $tmp[
"x"] =
"xaxis: { tickDecimals: 0 }";
396 if(!isset($tmp[
"y"]) && $this->integer_axis[
"y"])
398 $tmp[
"y"] =
"yaxis: { tickDecimals: 0 }";
403 $chart->setVariable(
"AXIS",
",".implode(
", ", $tmp));
406 return $chart->get();
411 $this->integer_axis[
"y"] = (bool)$a_status;
416 $this->integer_axis[
"x"] = (bool)$a_status;