|
1 | | -laravel-admin extension |
2 | | -====== |
| 1 | +# Use Echarts in laravel-admin |
3 | 2 |
|
| 3 | +## Installation |
4 | 4 |
|
| 5 | +```bash |
| 6 | +composer require jxlwqq/echarts |
| 7 | + |
| 8 | +php artisan vendor:publish --tag=laravel-admin-echarts |
| 9 | +``` |
| 10 | + |
| 11 | +## Configuration |
| 12 | + |
| 13 | +Open `config/admin.php`, add configurations that belong to this extension at `extensions` section. |
| 14 | + |
| 15 | +```php |
| 16 | + 'extensions' => [ |
| 17 | + 'echarts' => [ |
| 18 | + // Set to `false` if you want to disable this extension |
| 19 | + 'enable' => true, |
| 20 | + ] |
| 21 | + ] |
| 22 | +``` |
| 23 | + |
| 24 | +## Usage |
| 25 | + |
| 26 | +Create a view in views directory like `resources/views/admin/echarts.blade.php`, and add following codes: |
| 27 | +```html |
| 28 | +<!-- prepare a DOM container with width and height --> |
| 29 | +<div id="main" style="width: 600px;height:400px;"></div> |
| 30 | +<script type="text/javascript"> |
| 31 | + // based on prepared DOM, initialize echarts instance |
| 32 | + var myChart = echarts.init(document.getElementById('main')); |
| 33 | +
|
| 34 | + // specify chart configuration item and data |
| 35 | + var option = { |
| 36 | + title: { |
| 37 | + text: 'ECharts entry example' |
| 38 | + }, |
| 39 | + tooltip: {}, |
| 40 | + legend: { |
| 41 | + data:['Sales'] |
| 42 | + }, |
| 43 | + xAxis: { |
| 44 | + data: ["shirt","cardign","chiffon shirt","pants","heels","socks"] |
| 45 | + }, |
| 46 | + yAxis: {}, |
| 47 | + series: [{ |
| 48 | + name: 'Sales', |
| 49 | + type: 'bar', |
| 50 | + data: [5, 20, 36, 10, 10, 20] |
| 51 | + }] |
| 52 | + }; |
| 53 | +
|
| 54 | + // use configuration item and data specified to show chart |
| 55 | + myChart.setOption(option); |
| 56 | +</script> |
| 57 | +``` |
| 58 | + |
| 59 | +Then show it on the page |
| 60 | + |
| 61 | +```php |
| 62 | +class EchartsController extends Controller |
| 63 | +{ |
| 64 | + public function index(Content $content) |
| 65 | + { |
| 66 | + return $content |
| 67 | + ->header('Echarts') |
| 68 | + ->body(new Box('echarts demo', view('admin.echarts'))); |
| 69 | + } |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +For more usage, please refer to the official [website](https://echarts.apache.org/en/index.html) of echarts. |
| 74 | + |
| 75 | + |
| 76 | +License |
| 77 | +------------ |
| 78 | +Licensed under [The MIT License (MIT)](LICENSE). |
0 commit comments