77<a href =" https://packagist.org/packages/bbsnly/chartjs-php " ><img src =" https://poser.pugx.org/bbsnly/chartjs-php/license.svg " alt =" License " ></a >
88</p >
99
10- The package helps you to generate [ ChartJS] ( http://www.chartjs.org/ " ChartJS ")
11- element directly in PHP and translate it to JSON.
10+
11+ ** For non Laravel projects, please use the [ 1.2] ( https://github.com/bbsnly/chartjs-php/tree/1.2 ) branch**
12+
13+ This package helps you to generate [ ChartJS] ( http://www.chartjs.org/ " ChartJS ") element directly in PHP and translate it to JSON.
1214
1315## Install
14- ` composer require bbsnly/chartjs-php `
16+ Require this package with composer.
17+ ``` shell
18+ composer require bbsnly/chartjs-php
19+ ```
1520
16- ## Test
17- ` composer test `
21+ Laravel 5.5 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
22+
23+ If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php
24+ ``` php
25+ Bbsnly\ChartJs\ChartServiceProvider::class,
26+ ```
1827
1928## Requirements
2029* ` php >= 7.0 `
@@ -34,44 +43,37 @@ element directly in PHP and translate it to JSON.
3443Also it is possible to use the package with [ New Charts] ( http://www.chartjs.org/docs/latest/developers/charts.html )
3544using the ` Chart ` class
3645
37- ## How To
38- ### Create
39- ```
40- $chart = new Chart;
41- $chart->type = 'line';
42- $chart->toJson();
43- ```
44- and
45- ```
46- $chart = new LineChart;
47- $chart->toJson();
48- ```
49- provides the same result.
50-
51- ### Usage
46+ ## Usage
5247To personalize your chart you have three options:
5348* Using arrays
5449* Using attributes
5550* Using methods
5651
57- #### Examples
52+ ### Examples
5853Using arrays
59- ```
54+ ``` php
55+ $chart = app(Bbsnly\ChartJs\Chart::class);
56+
6057$chart->data([
6158 'labels' => ['Red', 'Green', 'Blue'],
62- 'datasets' => [{
63- 'data' => [5, 10, 20]
64- }]
59+ 'datasets' => [
60+ [
61+ 'data' => [5, 10, 20]
62+ ]
63+ ]
6564]);
6665
6766$chart->options([
6867 'responsive' => true
6968]);
69+
70+ $chart->toJson();
7071```
7172Using attributes
72- ```
73- $data = new Data( );
73+ ``` php
74+ $chart = app(Bbsnly\ChartJs\Chart::class );
7475
76+ $data = new Data();
7577$data->labels = ['Red', 'Green', 'Blue'];
7678
7779$dataset = new Dataset();
@@ -83,9 +85,13 @@ $chart->data($data);
8385$options = new Options();
8486$options->responsive = true;
8587$chart->options($options);
88+
89+ $chart->toJson();
8690```
8791Using methods
88- ```
92+ ``` php
93+ $chart = app(Bbsnly\ChartJs\Chart::class);
94+
8995$data = new Data;
9096
9197$data->datasets([
@@ -97,25 +103,22 @@ $chart->data($data);
97103$options = new Options();
98104$options->responsive(true);
99105$chart->options($options);
106+
107+ $chart->toJson();
100108```
101109### Config class
102110To configure your chart you can use the ` Config ` class directly or helpers
103111like ` Dataset ` or ` Options ` .
104112
105- You can extend it and add a helper for wherever you need (ex. ` Scales ` ).
113+ You can extend it and add a helper you need (ex. ` Scales ` ).
106114
107115If you decide to override the ` Config ` class you should implement
108116the ` ConfigInterface ` to be sure about the compatibility.
109117
110- ## Code Examples
111- You can find some examples
112- [ here] ( https://github.com/bbsnly/chartjs-php/tree/master/tests/examples " ChartJS PHP Examples ")
113118
114119## Contributing
115-
116120Thank you for considering contributing to the ChartJS PHP!
117121
118122## License
119-
120123The ChartJS PHP is open-sourced software licensed under the
121124[ MIT license] ( http://opensource.org/licenses/MIT ) .
0 commit comments