Exemplo n.º 1
0
 /**
  * Registers the required js files and script to initialize ChartJS plugin
  */
 protected function registerClientScript()
 {
     $id = $this->options['id'];
     $type = $this->type;
     $view = $this->getView();
     $data = !empty($this->data) ? Json::encode($this->data) : '{}';
     $options = !empty($this->clientOptions) ? Json::encode($this->clientOptions) : '{}';
     ChartJsAsset::register($view);
     $js = ";var chartJS_{$id} = new Chart(document.getElementById('{$id}').getContext('2d')).{$type}({$data}, {$options});";
     $js .= "if (typeof(document.getElementById('{$id}-legend')) != 'undefined' && document.getElementById('{$id}-legend') != null){document.getElementById('{$id}-legend').innerHTML = chartJS_{$id}.generateLegend();};";
     $view->registerJs($js);
 }
Exemplo n.º 2
0
 /**
  * Registers the required js files and script to initialize ChartJS plugin
  */
 protected function registerClientScript()
 {
     $id = $this->options['id'];
     $type = $this->type;
     $view = $this->getView();
     $data = !empty($this->data) ? Json::encode($this->data) : '{}';
     $options = !empty($this->clientOptions) ? Json::encode($this->clientOptions) : '{}';
     ChartJsAsset::register($view);
     $js = ";var chartJS_{$id} = new Chart(document.getElementById('{$id}').getContext('2d')).{$type}({$data}, {$options});";
     $view->registerJs($js);
 }
Exemplo n.º 3
0
 /**
  * Registers the required js files and script to initialize ChartJS plugin
  */
 protected function registerClientScript()
 {
     $id = $this->options['id'];
     $view = $this->getView();
     ChartJsAsset::register($view);
     $config = Json::encode(['type' => $this->type, 'data' => $this->data ?: new JsExpression('{}'), 'options' => $this->clientOptions ?: new JsExpression('{}')]);
     $js = ";var chartJS_{$id} = new Chart(\$('#{$id}'),{$config});";
     $view->registerJs($js);
 }