Hope you can help me out, I'm trying to set the data for the chart but I can't get it,
it works with the Manual data entry but not with the database, whenever I try foreach cakephp throw some erros,
here is my code.
public function index() {
$this->Result->recursive = 0;
$this->set('results', $this->Paginator->paginate());
//Get data from model
$this->set('result', $this->Result->find('first'));
$this->set('result', $this->Result->find('all');
//Setup data for chart
$chart = new GoogleCharts();
$chart->type("LineChart");
//Options array holds all options for Chart API
$chart->options(array('title' => "Recent Scores"));
$chart->columns(array(
//Each column key should correspond to a field in your data array
'event' => array(
//Tells the chart what type of data this is
'type' => 'string',
//The chart label for this column
'label' => 'Date'
),
'number' => array(
'type' => 'number',
'label' => 'result',
//Optional NumberFormat pattern
'format' => '#'
)
));
foreach($results as $result){
$chart->addRow(array('event' => $row['Result']['event'], 'score' => $row['Result']['score']));
}
//Set the chart for your view
$this->set(compact('chart'));
Hope you can help me out, I'm trying to set the data for the chart but I can't get it,
it works with the Manual data entry but not with the database, whenever I try foreach cakephp throw some erros,
here is my code.
public function index() { $this->Result->recursive = 0; $this->set('results', $this->Paginator->paginate());
$chart->type("LineChart");
//Options array holds all options for Chart API $chart->options(array('title' => "Recent Scores")); $chart->columns(array( //Each column key should correspond to a field in your data array 'event' => array( //Tells the chart what type of data this is 'type' => 'string',
//The chart label for this column
'label' => 'Date' ), 'number' => array( 'type' => 'number', 'label' => 'result', //Optional NumberFormat pattern 'format' => '#' ) ));
} //Set the chart for your view $this->set(compact('chart'));