/** * @param Chart $value * @return string */ public function render($value) { $data = $value->data(); if (!$data) { return '[no data]'; } $data = json_encode($data); $options = json_encode($value->options()); $type = $value->chartType(); $id = uniqid("{$type}-chart-"); return (string) new Element('div', [], [new Element('canvas', ['id' => $id]), new Element('script', [], ["\n var ctx = document.getElementById('{$id}').getContext('2d');\n new Chart(ctx).{$type}({$data}, {$options});\n "])]); }
/** * @param DataPoint[] $dataPoints */ public function __construct(array $dataPoints = []) { parent::__construct(); $this->dataPoints = $dataPoints; }
/** * LineChart constructor. * @param null|string[] $labels * @param DataSet[] $dataSets */ public function __construct(array $labels = null, array $dataSets = []) { parent::__construct(); $this->labels = $labels; $this->dataSets = $dataSets; }
protected function defaultOptions() { return array_merge(parent::defaultOptions(), ['showTooltips' => true, 'scaleShowHorizontalLines' => true, 'scaleShowLabels' => true, 'scaleLabel' => "<%=value%>", 'scaleArgLabel' => "<%=value%>", 'multiTooltipTemplate' => '<%=datasetLabel%>: <%=arg%>; <%=value%>', 'scaleBeginAtZero' => true, 'datasetStroke' => false]); }