Chartable Behavior
2 : Example
This small behavior is something I made to make models easily work with the cool OpenFlashChart "vendor" (http://teethgrinder.co.uk/open-flash-chart/) and the FlashChartHelper (http://bakery.cakephp.org/articles/view/open-flash-chart-helper-draw-charts-the-cake-way).
Model Class:
<?php class Transport extends AppModel
var $name = 'Transport';
var $actsAs = array('Chartable' =>
array ( 'numberField' => 'count' , 'labelField' => 'date' ) );
?>
Controller Class:
<?php class TransportsController extends AppController
var $name = 'Transports';
var $helpers = array('FlashChart');
var $paginate = array('limit' => 10);
function chart() {
$this->Transport->recursive = -1;
$this->set('transports', $this->paginate());
}
?>
View Template:
<?php
$flashChart->begin('100%','500');
$flashChart->setLabels('x',$data['labels']);
$flashChart->setData(array(
'Apples' => array(
'color' => '#330066',
'data' => $data['numbers'],
'graph_style' => 'bar_glass',
),
));
$flashChart->configureGrid( array(
'x_axis' => array( 'legend' => 'Date' ),
'y_axis' => array( 'legend' => '#Apples' )
));
$flashChart->setRange('y', 0, 1000);
echo $flashChart->render();
?>
<div class="paging">
<?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?>
| <?php echo $paginator->numbers();?>
<?php echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'));?>
</div>
Latest Comments