scottharwell / GoogleCharts

CakePHP Plugin for Google Charts Javascript API
26 stars 30 forks source link

Can't connect to the Data #15

Open kelpie278 opened 9 years ago

kelpie278 commented 9 years ago

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'));

}
shahariaazam commented 9 years ago

@kelpie278 inside your foreach loop where you are getting $results variable?