Code Monkey home page Code Monkey logo

phphc's Introduction

WIP php lib for Highcharts Build Status

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).

phphc's People

Contributors

benjabcn avatar petesiss avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.