首先,對不起,如果我要求關於這個問題的幫助,但我已經在這一工作了近一天了。我搜索了這個網站,並能找到類似於我的問題的帖子,但我無法讓它工作。CakePHP 2.7 GoogleChart插件
無論如何,我正在使用CakePHP 2.x,並且需要通過圖表顯示報表。我看到CakePHP CakePHP GoogleCharts Plugin by Scott Harwell的這個插件。我做了一切一步一步,不知何故,我的觀點一直顯得空虛。我確定這不是因爲衝突的文件,所以我決定創建一個新的CakePHP項目,不幸的是,它不起作用。
這裏是我的代碼:
控制器:
<?php
App::uses('AppController', 'Controller');
App::uses('GoogleCharts', 'GoogleCharts.Lib');
class ChartsController extends AppController {
public $uses = array('Student');
public $helpers = array('GoogleCharts.GoogleCharts');
public function test_chart(){
$student= $this->Student->getStudentAges();
$studentAgesChart= new GoogleCharts();
$studentAgesChart->type('LineChart');
$studentAgesChart->options(array('title' => "Student Ages"));
$studentAgesChart->columns(array(
//Each column key should correspond to a field in your data array
'name' => array(
'type' => 'string',
'label' => 'Student Name'
),
'age' => array(
'type' => 'number',
'label' => 'Student Age'
)
));
foreach($student as $row){
$studentAgesChart->addRow(array('age' => $row['Student']['age'], 'name' => $row['Student']['name']));
}
$this->set(compact('studentAgesChart'));
debug($studentAgesChart);
}
}
?>
查看:
<div id="chart_div" >
<?php
$this->GoogleCharts->createJsChart($studentAgesChart);
?>
</div>
調試($ studentAgesChart):
object(GoogleCharts) {
[private] type => 'LineChart'
[private] columns => array(
'name' => array(
'type' => 'string',
'label' => 'Student Name'
),
'age' => array(
'type' => 'number',
'label' => 'Student Age'
)
)
[private] rows => array(
(int) 0 => array(
(int) 0 => 'Student 1',
(int) 1 => '17'
),
(int) 1 => array(
(int) 0 => 'Student 2',
(int) 1 => '16'
)
)
[private] options => array(
'width' => (int) 400,
'height' => (int) 300,
'title' => 'Student Ages',
'titleTextStyle' => array(
'color' => 'red'
)
)
[private] callbacks => array()
[private] div => 'chart_div'
}
型號:
public function getStudentAges(){
$student_ages = $this->find('all',
array(
'order' => array('Student.name' => 'ASC'),
'limit' => 3,
'fields' => array(
'Student.name',
'Student.age'
)
)
);
return $student_ages;
}
我看到它的方式,它不包含任何錯誤,但我的觀點是空的。