Coder Social home page Coder Social logo

martingalovic / lavacharts Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kevinkhill/lavacharts

0.0 2.0 0.0 6.3 MB

Lavacharts is a graphing / charting library for PHP 5.4+ that wraps Google's Javascript Chart API.

Home Page: http://lavacharts.com

License: Other

JavaScript 2.63% PHP 97.37%

lavacharts's Introduction

Lavacharts v3.0

Total Downloads License Minimum PHP Version Gitter PayPayl

Lavacharts is a graphing / chart library for PHP5.4+ that wraps Google's Javascript Chart API

Stable: Current Release Build Status Coverage Status

Dev: Development Release Build Status Coverage Status

Version 3.0

Upgrade guide: Migrating from 2.5.x to 3.0.x

Package Features

  • Lava.js module for interacting with charts client-side
    • AJAX data reloading
    • Fetching charts
    • Events integration
  • Column Formatters
  • Column Roles
  • Blade template extensions for laravel
  • Twig template extensions for Symfony
  • Carbon support for date/datetime/timeofday columns
  • Now supporting 12 Charts!
    • Area, Bar, Calendar, Column, Combo, Donut, Gauge, Geo, Line, Pie, Scatter, Table
  • DataTablePlus package can be added to parse CSV files or Eloquent collections into DataTables.

For complete documentation, please visit lavacharts.com


Installing

In your project's main composer.json file, add this line to the requirements:

"khill/lavacharts": "~3.0"

Run Composer to install Lavacharts:

$ composer update

Framework Agnostic

If you are using Lavacharts with Silex, Lumen or your own Composer project, that's no problem! Just make sure to: require 'vendor/autoload.php'; within you project and create an instance of Lavacharts: $lava = new Khill\Lavacharts\Lavacharts;

Laravel

To integrate lavacharts into Laravel, a ServiceProvider has been included.

Laravel 5.x

Register Lavacharts in your app by adding this line to the end of the providers array in config/app.php:

<?php
// config/app.php

// ...
'providers' => [
    ...

    Khill\Lavacharts\Laravel\LavachartsServiceProvider::class,
],

The Lava:: alias will be registered automatically via the service provider.

Laravel 4.x

Register Lavacharts in your app by adding this line to the end of the providers array in app/config/app.php:

<?php
// app/config/app.php

// ...
'providers' => array(
    // ...

    "Khill\Lavacharts\Laravel\LavachartsServiceProvider",
),

The Lava:: alias will be registered automatically via the service provider.

Symfony 2.x

Also included is a Bundle for Symfony to create a service that can be pulled from the Container.

Add Bundle

Add the bundle to the AppKernel:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Khill\Lavacharts\Symfony\Bundle\LavachartsBundle(),
        );

        // ...
    }

    // ...
}

Import Config

Add the service definition to the app/config/config.yml file

imports:
  # ...
  - { resource: @LavachartsBundle/Resources/config/services.yml

Usage

The creation of charts is separated into two parts: First, within a route or controller, you define the chart, the data table, and the customization of the output.

Second, within a view, you use one line and the library will output all the necessary javascript code for you.

Basic Example

Here is an example of the simplest chart you can create: A line chart with one dataset and a title, no configuration.

Controller

    $stocksTable = $lava->DataTable();  // Lava::DataTable() if using Laravel

    $stocksTable->addDateColumn('Day of Month')
                ->addNumberColumn('Projected')
                ->addNumberColumn('Official');

    // Random Data For Example
    for ($a = 1; $a < 30; $a++)
    {
        $rowData = [
          "2014-8-$a", rand(800,1000), rand(800,1000)
        ];

        $stocksTable->addRow($rowData);
    }

Arrays work for datatables as well...

  $stocksTable->addColumns([
    ['date', 'Day of Month'],
    ['number', 'Projected'],
    ['number', 'Official']
  ]];

...and for setting chart options!

  $lava->LineChart('Stocks', $stocksTable, ['title' => 'Stock Market Trends']);

View

If you are using Laravel and the Blade templating engine, there are some nifty extensions thrown in for a cleaner view

@linechart('Stocks', 'stocks-div');
// Behind the scenes this just calls Lava::renderLineChart('Stocks', 'stocks-div')
// which is an alias for the render method, seen below

Or you can use the new render method, passing in the chart type, label, and element id.

echo Lava::render('LineChart', 'Stocks', 'stocks-div');

This is all assuming you already have a div in your page with the id "stocks-div": <div id="stocks-div"></div>

If you don't have a div ready to accept the charts, add one more parameter to @linechart() or render() and it will be created for you.

Add true to for the library to create a plain div, or an array with keys width & height

Example:

@linechart('Stocks', 'stocks-div', true)
// Or
echo Lava::render('LineChart', 'Stocks', 'stocks-div', ['width'=>1024, 'height'=>768]);

Changelog

The complete changelog can be found here

lavacharts's People

Contributors

antoniotajuelo avatar darklotus avatar kevinkhill avatar marcusirgens avatar mpociot avatar rajivseelam avatar stevebauman avatar stonos avatar

Watchers

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