Skip to content

Commit b11b396

Browse files
committed
first commit
1 parent ea970ed commit b11b396

File tree

5 files changed

+189
-0
lines changed

5 files changed

+189
-0
lines changed

README.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
Use Chartjs in laravel-admin
2+
======
3+
4+
5+
## Installation
6+
7+
```bash
8+
composer require laravel-admin-ext/chartjs
9+
10+
php artisan vendor:publish --tag=laravel-admin-chartjs
11+
```
12+
13+
## Configuration
14+
15+
Open `config/admin.php`, add configurations that belong to this extension at `extensions` section.
16+
17+
```php
18+
19+
'extensions' => [
20+
21+
'daterangepicker' => [
22+
23+
// Set to `false` if you want to disable this extension
24+
'enable' => true,
25+
]
26+
]
27+
28+
```
29+
30+
## Usage
31+
32+
Create a view in views directory like `resources/views/admin/chart.blade.php`, and add following codes:
33+
```html
34+
<canvas id="myChart" width="400" height="400"></canvas>
35+
<script>
36+
$(function () {
37+
var ctx = document.getElementById("myChart").getContext('2d');
38+
var myChart = new Chart(ctx, {
39+
type: 'bar',
40+
data: {
41+
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
42+
datasets: [{
43+
label: '# of Votes',
44+
data: [12, 19, 3, 5, 2, 3],
45+
backgroundColor: [
46+
'rgba(255, 99, 132, 0.2)',
47+
'rgba(54, 162, 235, 0.2)',
48+
'rgba(255, 206, 86, 0.2)',
49+
'rgba(75, 192, 192, 0.2)',
50+
'rgba(153, 102, 255, 0.2)',
51+
'rgba(255, 159, 64, 0.2)'
52+
],
53+
borderColor: [
54+
'rgba(255,99,132,1)',
55+
'rgba(54, 162, 235, 1)',
56+
'rgba(255, 206, 86, 1)',
57+
'rgba(75, 192, 192, 1)',
58+
'rgba(153, 102, 255, 1)',
59+
'rgba(255, 159, 64, 1)'
60+
],
61+
borderWidth: 1
62+
}]
63+
},
64+
options: {
65+
scales: {
66+
yAxes: [{
67+
ticks: {
68+
beginAtZero:true
69+
}
70+
}]
71+
}
72+
}
73+
});
74+
});
75+
</script>
76+
77+
```
78+
79+
Then show it on the page
80+
81+
```php
82+
class ChartjsController extends Controller
83+
{
84+
public function index(Content $content)
85+
{
86+
return $content
87+
->header('Chartjs')
88+
->body(view('admin.chartjs'));
89+
}
90+
}
91+
```
92+
93+
## Donate
94+
95+
> Help keeping the project development going, by donating a little. Thanks in advance.
96+
97+
[![PayPal Me](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/zousong)
98+
99+
![-1](https://cloud.githubusercontent.com/assets/1479100/23287423/45c68202-fa78-11e6-8125-3e365101a313.jpg)
100+
101+
License
102+
------------
103+
Licensed under [The MIT License (MIT)](LICENSE).

composer.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "laravel-admin-ext/chartjs",
3+
"description": "Use Chartjs in laravel-admin",
4+
"type": "library",
5+
"keywords": ["laravel-admin", "extension", "chartjs"],
6+
"homepage": "https://github.com/laravel-admin-ext/chartjs",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "song",
11+
"email": "[email protected]"
12+
}
13+
],
14+
"require": {
15+
"php": ">=7.0.0",
16+
"encore/laravel-admin": "*"
17+
},
18+
"require-dev": {
19+
"phpunit/phpunit": "~6.0"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"Encore\\Chartjs\\": "src/"
24+
}
25+
},
26+
"extra": {
27+
"laravel": {
28+
"providers": [
29+
"Encore\\Chartjs\\ChartjsServiceProvider"
30+
]
31+
32+
}
33+
}
34+
}

resources/assets/Chart.bundle.min.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Chartjs.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Encore\Chartjs;
4+
5+
use Encore\Admin\Extension;
6+
7+
class Chartjs extends Extension
8+
{
9+
public $name = 'chartjs';
10+
11+
public $assets = __DIR__.'/../resources/assets';
12+
}

src/ChartjsServiceProvider.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Encore\Chartjs;
4+
5+
use Encore\Admin\Admin;
6+
use Illuminate\Support\ServiceProvider;
7+
8+
class ChartjsServiceProvider extends ServiceProvider
9+
{
10+
/**
11+
* {@inheritdoc}
12+
*/
13+
public function boot(Chartjs $extension)
14+
{
15+
if (! Chartjs::boot()) {
16+
return ;
17+
}
18+
19+
if ($this->app->runningInConsole() && $assets = $extension->assets()) {
20+
$this->publishes(
21+
[$assets => public_path('vendor/laravel-admin-ext/chartjs')],
22+
'laravel-admin-chartjs'
23+
);
24+
}
25+
26+
Admin::booting(function () {
27+
Admin::js('vendor/laravel-admin-ext/chartjs/Chart.bundle.min.js');
28+
});
29+
}
30+
}

0 commit comments

Comments
 (0)