laravel-admin-ext / sparkline
将 jQuery sparkline 集成到 laravel-admin 中
v1.0.0
2018-09-25 17:12 UTC
Requires
- php: >=7.0.0
- encore/laravel-admin: ~1.6
Requires (Dev)
- phpunit/phpunit: ~6.0
This package is auto-updated.
Last update: 2024-09-13 22:39:24 UTC
README
截图
安装
composer require laravel-admin-ext/sparkline php artisan vendor:publish --tag=laravel-admin-sparkline
配置
打开 config/admin.php
文件,在 extensions
部分添加此扩展的配置。
'extensions' => [ 'sparkline' => [ // Set to `false` if you want to disable this extension 'enable' => true, ] ]
用法
用作图表面板
在 views 目录中创建一个视图,例如 resources/views/admin/sparkline/bar.blade.php
,并添加以下代码
<div class="row text-center"> <div id="sparkline-bar"></div> </div> <script> $(function () { $("#sparkline-bar").sparkline([6,4,8, 9, 10, 5, 13, 18, 21, 7, 9], { type: 'bar', width: '100%', height: 150, barSpacing: 3, barWidth: 20, barColor: "#f39c12" }); }); </script>
然后在页面上显示它
class SparklineController extends Controller { public function index(Content $content) { return $content ->header('jQuery sparkline') ->body(new Box('Bar chart', view('admin.sparkline.bar'))); } }
有关更多用法,请参阅 jQuery sparkline 的官方 文档。
在网格列中使用
如果列 scores
返回一个数组类型的值,并且你想要将此列显示为内联折线图
$grid->scores()->sparkline('line'); // add options $grid->scores()->sparkline('line', [ 'width' => 100, 'spotRadius' => 2 ]);
还有其他 6 种图表类型,例如 bar
、pie
、box
、tristate
、bullet
、discrete
,所有选项都可以在 jQuery sparkline 的官方 文档 中找到。
捐赠
通过捐赠一小笔资金来帮助项目持续发展。提前感谢。
许可
在 MIT 许可证 (MIT) 下授权。