HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbGoogleVisualizationChart.php
Go to the documentation of this file.
1 <?php
18 class TbGoogleVisualizationChart extends CWidget
19 {
23  public $containerId;
24 
30 
35  public $data = array();
36 
41  public $options = array();
42 
46  public $htmlOptions = array();
47 
51  public function run()
52  {
53  $id = $this->getId();
54  $this->htmlOptions['id'] = $id;
55  // if no container is set, it will create one
56  if ($this->containerId == null) {
57  $this->containerId = 'div-chart' . $id;
58  echo '<div ' . CHtml::renderAttributes($this->htmlOptions) . '></div>';
59  }
60  $this->registerClientScript();
61  }
62 
66  public function registerClientScript()
67  {
68  $id = $this->getId();
69  $jsData = CJavaScript::jsonEncode($this->data);
70  $jsOptions = CJavaScript::jsonEncode($this->options);
71 
72  $script = '
73  google.setOnLoadCallback(drawChart' . $id . ');
74  var ' . $id . '=null;
75  function drawChart' . $id . '() {
76  var data = google.visualization.arrayToDataTable(' . $jsData . ');
77 
78  var options = ' . $jsOptions . ';
79 
80  ' . $id . ' = new google.visualization.' . $this->visualization . '(document.getElementById("' . $this->containerId . '"));
81  ' . $id . '.draw(data, options);
82  }';
83 
85  $cs = Yii::app()->getClientScript();
86  $cs->registerScriptFile('https://www.google.com/jsapi');
87  $cs->registerScript(
88  __CLASS__ . '#' . $id,
89  'google.load("visualization", "1", {packages:["corechart"]});',
90  CClientScript::POS_HEAD
91  );
92  $cs->registerScript($id, $script, CClientScript::POS_HEAD);
93  }
94 }