Package Data | |
---|---|
Maintainer Username: | kevinkhill |
Maintainer Contact: | kevinkhill@gmail.com (Kevin Hill) |
Package Create Date: | 2013-08-29 |
Package Last Update: | 2024-04-26 |
Home Page: | http://lavacharts.com |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-08 03:08:20 |
Package Statistics | |
---|---|
Total Downloads: | 1,546,339 |
Monthly Downloads: | 20,221 |
Daily Downloads: | 1,045 |
Total Stars: | 620 |
Total Watchers: | 23 |
Total Forks: | 142 |
Total Open Issues: | 22 |
Lavacharts is a graphing / chart library for PHP5.4+ that wraps the Google Chart API.
In your project's main composer.json
file, add this line to the requirements:
"khill/lavacharts": "^3.1"
Run Composer to install Lavacharts:
$ composer update
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;
To integrate Lavacharts into Laravel, a ServiceProvider has been included.
Thanks to the fantastic new Package Auto-Discovery feature added in 5.5, you're ready to go, no registration required :+1:
To modify the default configuration of Lavacharts, datetime formats for datatables or adding your maps api key...
Publish the configuration with php artisan vendor:publish --tag=lavacharts
Register Lavacharts in your app by adding these lines to the respective arrays found in config/app.php
:
<?php
// config/app.php
// ...
'providers' => [
// ...
Khill\Lavacharts\Laravel\LavachartsServiceProvider::class,
],
// ...
'aliases' => [
// ...
'Lava' => Khill\Lavacharts\Laravel\LavachartsFacade::class,
]
To modify the default configuration of Lavacharts, datetime formats for datatables or adding your maps api key...
Publish the configuration with php artisan vendor:publish --tag=lavacharts
Register Lavacharts in your app by adding these lines to the respective arrays found in app/config/app.php
:
<?php
// app/config/app.php
// ...
'providers' => array(
// ...
"Khill\Lavacharts\Laravel\LavachartsServiceProvider",
),
// ...
'aliases' => array(
// ...
'Lava' => "Khill\Lavacharts\Laravel\LavachartsFacade",
)
To modify the default configuration of Lavacharts, datetime formats for datatables or adding your maps api key...
Publish the configuration with php artisan config:publish khill/lavacharts
The package also includes a Bundle for Symfony to enable Lavacharts as a service that can be pulled from the Container.
Add the bundle to the registerBundles method in the AppKernel, found at app/AppKernel.php
:
<?php
// app/AppKernel.php
class AppKernel extends Kernel
{
// ..
public function registerBundles()
{
$bundles = array(
// ...
new Khill\Lavacharts\Symfony\Bundle\LavachartsBundle(),
);
}
}
Add the service definition to the app/config/config.yml
file
imports:
# ...
- { resource: "@LavachartsBundle/Resources/config/services.yml"
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.
Here is an example of the simplest chart you can create: A line chart with one dataset and a title, no configuration.
Setting up your first chart.
$data = $lava->DataTable();
$data->addDateColumn('Day of Month')
->addNumberColumn('Projected')
->addNumberColumn('Official');
// Random Data For Example
for ($a = 1; $a < 30; $a++) {
$rowData = [
"2017-4-$a", rand(800,1000), rand(800,1000)
];
$data->addRow($rowData);
}
Arrays work for datatables as well...
$data->addColumns([
['date', 'Day of Month'],
['number', 'Projected'],
['number', 'Official']
]);
Or you can use \Khill\Lavacharts\DataTables\DataFactory
to create DataTables in another way
Customize your chart, with any options found in Google's documentation. Break objects down into arrays and pass to the chart.
$lava->LineChart('Stocks', $data, [
'title' => 'Stock Market Trends',
'animation' => [
'startup' => true,
'easing' => 'inAndOut'
],
'colors' => ['blue', '#F4C1D8']
]);
The chart will needs to be output into a div on the page, so an html ID for a div is needed.
Here is where you want your chart <div id="stocks-div"></div>
$lava->LineChart('Stocks', $data, 'stocks-div');
$lava->LineChart('Stocks', $data, [
'elementId' => 'stocks-div'
'title' => 'Stock Market Trends'
]);
$lava->LineChart('Stocks', $data, [
'title' => 'Stock Market Trends'
], 'stocks-div');
Pass the main Lavacharts instance to the view, because all of the defined charts are stored within, and render!
<?= $lava->render('LineChart', 'Stocks', 'stocks-div'); ?>
Or if you have multiple charts, you can condense theh view code withL
<?= $lava->renderAll(); ?>
The complete changelog can be found here