mlantz/laravelcharts

This package is abandoned and no longer maintained. No replacement package was suggested.

ChartJs for Laravel forked from fx3costa/laravelchartjs

1.2.5 2016-02-15 18:20 UTC

This package is not auto-updated.

Last update: 2020-01-08 21:15:05 UTC


README

This is a simple package that enables to use simple and quick reports and graphs using the Chart.js Javascript library from Nick Downie.

Setup:

composer require mlantz/laravelcharts

And add the Service Provider in your file config/app.php:

Mlantz\Laravelcharts\Providers\ChartsServiceProvider::class

Finally, publish the package to use a configuration file that allows dynamically choose the colors of the graphics according to the chart type and datasets.

php artisan vendor:publish

config file:

<?php
return [
    'colours' => [
        'bar' => [
            'rgba(220,220,220,0.5)',
            'rgba(151,187,205,0.8)',
            'rgba(24, 164, 103, 0.7)',
        ],
        'line' => [
            'rgba(220,220,220,0.5)',
            'rgba(151,187,205,0.8)',
            'rgba(24, 164, 103, 0.7)',
        ],
        'pie' => [
            [
                'colour' => "#F7464A",
                'highlight' => "#FF5A5E"
            ],
        ]
    ],
];

Where we have color setting in accordance with the chart type and according to the number of datasets that you will use.

ChartJS is added to your view via a CDN - you can opt out in the config:

includeChartJs: true

Usage:

Example of simple use, in a view or whatever you want to display the graphic:

1 - Bar Chart:

<div class="container-fluid">
    <canvas id="barGraph" style="width:50%;"></canvas>
</div>

<?php
    $data = array(
        'Jan' => array(33),
        'Feb' => array(32),
        'Mar' => array(12)
    );
?>

{!! app()->chartbar->render("barGraph", $data) !!}

Where $data is an array of information, the key serves as Label and the value is the value of the information itself. If you need more than one dataset - ie two data to the same label as if it were old and current value - just add values to the value of array, for example: 'March' => array (12, 25,. .., n)

2 - Pie Chart:

<div class="container-fluid">
    <canvas id="pieGraph" style="width:50%;"></canvas>
</div>

<?php
    $data = array(
        'Ferdinand' => 32,
        'Felix' => 37,
        'John' => 12
    );
?>

{!! app()->chartpie->render("pieGraph", $data) !!}

Where $data is an array of information, the key serves as Label and the value is the value of the information itself. The color and highlight color is random according to what was defined in the configuration file

3 - Line Chart:

<div class="container-fluid">
    <canvas id="lineGraph" style="width:50%;"></canvas>
</div>

<?php
    $data = array(
        'Ferdinand' => array(32),
        'Felix' => array(37),
        'John' => array(12)
    );
?>

{!! app()->chartline->render("lineGraph", $data) !!}

Any questions or suggestions please create issues on GitHub. Thanks.