Last Updated: February 25, 2016
· my3recipes

Using Highchart in CakePHP

I will quickly show how to use Highchart with CakePHP 2.x.

What is Highchart?

<a href="">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=""> demo</a> page.

There is also a <a href="">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:

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");?>

1 Response
Add your response

help cakephp and highcharts conection mysql

over 1 year ago ·