2017 © Pedro Peláez
 

library morris-graphs

Generate morris graphs for laravel

image

feijs/morris-graphs

Generate morris graphs for laravel

  • Saturday, September 19, 2015
  • by Feijs
  • Repository
  • 1 Watchers
  • 3 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

MorrisGraphs

, (*1)

This package provides a class to easily generate dynamic graphs with Morris.js, (*2)

Installation

Add the package in composer.json and run composer update, (*3)

"require": {
    "feijs/morris-graphs": "dev-master"
}

Add the ServiceProvider to the providers in config\app.php, (*4)

'Feijs\MorrisGraphs\MorrisGraphsServiceProvider'

And publish the package assets:, (*5)

php artisan asset:publish "feijs/morris-graphs"

Usage

Creating a graph

Create a Factory object and pass this to a view, (*6)

use Feijs\MorrisGraphs\Factory as Graph;

public function show()
{
    $graph = new Graph();
    return View::make('views.index')->with('graph', $graph)
}

Then in your view include the following:, (*7)

{{ $graph->includes() }}    //Preferably once per page

{{ $graph->div() }}         //Where you want to place the graph

{{ $graph->ranges('7', '14', 21) }}     //Add buttons for data ranges

{{ $graph->dynamic($source_url, ['quantity1', 'quantity2']) }}  

//Or

{{ $graph->fixed([$source_data], ['quantity1', 'quantity2']) }} 

For Donut graphs the second parameter may be ommitted, (*8)

Data

Source data should be organised as follows:, (*9)

[ 
    ['x-key' => 'x-value', 'y1' => 'y1-value', 'y2' => `y2-value`, ...],
    ['x-key' => 'x-value', 'y1' => 'y1-value', 'y2' => `y2-value`, ...],
    ...
]

Except for donuts graphs, where it should be:, (*10)

[ 
    ['label' => 'Label1', 'value' => 'Value1'],
    ['label' => 'Label2', 'value' => 'Value2'],
    ...
]

Settings

To customize graph settings you can call the following setters, (*11)

Horizontal key

Must match the horizontal key in the dataset, defaults to x, (*12)

$graph->setXKey('segment');

Graph type

Choose from Bar, Line, Area, Donut, defaults to Bar, (*13)

$graph->setGraphType('Donut');

Id

This id will match the script with the the div, (*14)

$graph->setGraphId('1234');

Height

The height of the graph, defaults to 250px, (*15)

$graph->setHeight('300px');

Label translations

You can specify a file with translations for the graph labels and error message(s) in the config, (*16)

  • Publish the package config files
php artisan config:publish "feijs/morris-graphs"
  • Set the translation file in translations.labels or translation.messages

The Versions

19/09 2015

dev-master

9999999-dev

Generate morris graphs for laravel

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Mike Feijs