Using Highchart in CakePHP
I will quickly show how to use Highchart with CakePHP 2.x.
What is Highchart?
<a href="http://www.highcharts.com/">Highcharts</a> is a charting library written in pure HTML5/JavaScript, offering intuitive, interactive charts to your web site or web application.
It's a great library with lots of chart types and features. Check <a href="http://www.highcharts.com/demo/"> demo</a> page.
There is also a <a href="https://github.com/ghunti/HighchartsPHP">HighchartsPHP</a> wrapper for the Highchart js library. To use it you must download it and put into vendors folder.
Then, load and use it in your CakePHP app's controller:
<?php
App::import('Vendor', 'HighchartsPHP/Highchart');
class ChartsController extends AppController {
public function index() {
$chart = new Highchart();
$chart->chart = array(
'renderTo' => 'container', // div ID where to render chart
'type' => 'line'
);
$chart->series[0]->name = 'Tokyo';
$chart->series[0]->data = array(7.0, 6.9, 9.5);
$this->set( compact( 'chart' ) );
}
}
So, controller is prepared to generate chart. Now you need to show it in view:
<?php $chart->printScripts(); ?>
<script type="text/javascript">
<?php echo $chart->render("chart");?>
</script>
Written by Mindaugas
Related protips
1 Response
help cakephp and highcharts conection mysql
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#