petesiss/phphc

Wrapper for HighCharts js charting lib

This package's canonical repository appears to be gone and the package has been frozen as a result. Email us for help if needed.

dev-master 2015-11-04 10:38 UTC

This package is not auto-updated.

Last update: 2024-01-20 10:46:24 UTC


README

Wrapper for highcharts js lib, allowing for easy config of charts via php arrays.

<?php

use Petesiss\PhpHc\ChartFactory;
use Petesiss\PhpHc\Renderer\Renderer;

$factory = new ChartFactory();

$chart = $factory->create()
    ->setChart(array('renderTo' => 'container', 'type' => 'line'))
    ->setTitle(array('text' => 'Traffic Flow'))
    ->setXAxis(array('categories' => array('Mon', 'Tue', 'Wed', 'Thurs', 'Fri')))
    ->setYAxis(array('title' => array('text' => 'Vehicles per minute')))
;

// add data series
$chart->addSeries('Main Street', array(44, 30, 34, 29, 48));
$chart->addSeries('Tower Road', array(29, 24, 27, 24, 28));

$renderer = new Renderer();

echo $renderer->render($chart);

Once a chart is created it can be configured using php arrays matching the highcharts API (http://api.highcharts.com/highcharts). There are accessor methods for each of the top level items - some of these shown in the example above.

The script block for the chart js can be easily rendered using the renderer as in the example. For more flexability just take the json from $chart->getJson() and deal with the rendering as required.

##Installation

Use composer to install, and make use of the autoload file composer will generate.

####Add to your composer.json

{
    "require": {
        "petesiss/phphc": "dev-master"
    }
}

####Then update your project dependencies

php composer.phar update petesiss/phphc

####Require composers generated autoload file

<?php
require 'vendor/autoload.php';

Alternatively the lib follows the PSR-0 convention so you can clone the repo and use any compatible autoloader.

This lib doesnt redistribute the highcharts js - you need to include that in your project yourself. It is currently available via the highcharts CDN (http://code.highcharts.com).