雪软/sparkline

将jQuery sparkline集成到laravel-admin

v1.0.2 2023-01-27 11:21 UTC

This package is auto-updated.

Last update: 2024-09-27 14:50:56 UTC


README

截图

qq20180926-010814

qq20180926-010742

安装

composer require snowsoft/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种图表类型,如barpieboxtristatebulletdiscrete,所有选项都可以在jQuery sparkline的官方文档中找到。

许可

许可协议为MIT许可(MIT)