Skip to content

Commit

Permalink
Merge pull request #197 from lex111/patch-1
Browse files Browse the repository at this point in the history
Improve README.md
  • Loading branch information
kevinkhill committed Apr 18, 2017
2 parents 2364a9a + 3463b6c commit b4d021e
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions README.md
Expand Up @@ -6,7 +6,7 @@
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/kevinkhill/lavacharts?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![PayPayl](https://img.shields.io/badge/paypal-donate-yellow.svg?style=plastic)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FLP6MYY3PYSFQ)

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

Stable:
[![Current Release](https://img.shields.io/github/release/kevinkhill/lavacharts.svg?style=plastic)](https://github.com/kevinkhill/lavacharts/releases)
Expand All @@ -22,7 +22,7 @@ Dev:
## Package Features
- **Updated!** Any option for customizing charts that Google supports, Lavacharts should as well. Just use the chart constructor to assign any customization options you wish!
- Visit [Google's Chart Gallery](https://developers.google.com/chart/interactive/docs/gallery) for details on available options
- Custom javascript module for interacting with charts client-side
- Custom JavaScript module for interacting with charts client-side
- AJAX data reloading
- Fetching charts
- Events integration
Expand Down Expand Up @@ -57,7 +57,7 @@ If you are using Lavacharts with Silex, Lumen or your own Composer project, that


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

### Laravel 5.x
Register Lavacharts in your app by adding these lines to the respective arrays found in `config/app.php`:
Expand All @@ -67,14 +67,14 @@ Register Lavacharts in your app by adding these lines to the respective arrays f

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

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

// ...
'aliases' => [
...
// ...

'Lava' => Khill\Lavacharts\Laravel\LavachartsFacade::class,
]
Expand Down Expand Up @@ -140,25 +140,24 @@ imports:
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.
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
Setting up your first chart
Setting up your first chart.

#### Data
```php
$data = $lava->DataTable();

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

// Random Data For Example
for ($a = 1; $a < 30; $a++)
{
for ($a = 1; $a < 30; $a++) {
$rowData = [
"2017-4-$a", rand(800,1000), rand(800,1000)
];
Expand All @@ -179,7 +178,7 @@ $data->addColumns([
Or you can `use \Khill\Lavacharts\DataTables\DataFactory` [to create DataTables in another way](https://gist.github.com/kevinkhill/0c7c5f6211c7fd8f9658)

#### Chart Options
Customize your chart, with any options found in google's documentation. Break objects down into arrays and pass to the chart.
Customize your chart, with any options found in Google's documentation. Break objects down into arrays and pass to the chart.
```php
$lava->LineChart('Stocks', $data, [
'title' => 'Stock Market Trends',
Expand All @@ -196,25 +195,25 @@ The chart will needs to be output into a div on the page, so an html ID for a di
Here is where you want your chart `<div id="stocks-div"></div>`
- If no options for the chart are set, then the third parameter is the id of the output:
```php
$lava->LineChart('Stocks', $data, 'stocks-div');
$lava->LineChart('Stocks', $data, 'stocks-div');
```
- If there are options set for the chart, then the id may be included in the options:
```php
$lava->LineChart('Stocks', $data, [
'elementId' => 'stocks-div'
'title' => 'Stock Market Trends'
]);
$lava->LineChart('Stocks', $data, [
'elementId' => 'stocks-div'
'title' => 'Stock Market Trends'
]);
```
- The 4th parameter will also work:
```php
$lava->LineChart('Stocks', $data, [
'title' => 'Stock Market Trends'
], 'stocks-div');
$lava->LineChart('Stocks', $data, [
'title' => 'Stock Market Trends'
], 'stocks-div');
```


## View
Pass the main lavacharts instance to the view, because all of the defined charts are stored within, and render!
Pass the main Lavacharts instance to the view, because all of the defined charts are stored within, and render!
```php
<?= $lava->render('LineChart', 'Stocks', 'stocks-div'); ?>
```
Expand Down

0 comments on commit b4d021e

Please sign in to comment.