Wiki

Clone wiki

highcharts-php / Home

Welcome

What is highcharts-php

highcharts-php is a PHP library to interact with the Highcharts JS charting library.

What is Highcharts

Reading from the official documentation, "Highcharts is a charting library written in pure JavaScript, offering an easy way of adding interactive charts to your web site or web application".

The Highcharts JS libraries are available at: www.highcharts.com and they are free for non commercial use. For commercial usage, please refers to the license and pricing section of their website.

Again, the highcharts-php project has nothing to do with the Highcharts projects. The authors are different and the two projects don't share any single line of code.

Why highcharts-php

The reason behind the highcharts-php project is to offer a useful tool to PHP developers to automatically generate Highcharts JS code starting from some PHP data.

Installation

To use this library, you will need the Highcharts JS libraries installed.

After that, you can simply create your Highcharts graph like this:

        // Include the library
        require_once('highcharts.php');

        // These are your data
        $data1 = array();
        $data2 = array();
        $data3 = array();

        // Convert your data arrays by doing:
        $d1 = new HighchartsArray($data1);
        $d2 = new HighchartsArray($data2);
        $d3 = new HighchartsArray($data3);

        // Create an option array for your graph.
        // Refers to the official Highcharts reference page for a list of the available options.
        // The page is available at:
        // http://www.highcharts.com/ref/
        $options = array(
                         'chart' => array(
                                          'renderTo' => 'my_graph',
                                          'defaultSeriesType' => 'line'
                                          ),
                         'title' => array(
                                          'text' => 'my_title'
                                          ),
                         'xAxis' => array(
                                          'categories' => $data1,
                                          'title' => 'x_axis_title'
                                          ),
                         'yAxis' => array(
                                          'title' => array(
                                                           'text' => 'y_axis_title'
                                                           )
                                          ),
                         'series' => array(
                                           array(
                                                 'name' => 'Data 1',
                                                 'data' => $data1
                                                 ),
                                           array(
                                                 'name' => 'Data 2',
                                                 'data' => $data2
                                                 )
                                           )
                         );

        // Generate your chart
        $chart = new Highcharts('my_graph', $options);

       // Enjoy your new chart
        echo $chart->getCode();
        echo '<div id="my_graph" width="500" height="300"> </div>';

Updated