百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
L

laravel-easy-metrics

> 后端框架
开源

轻松、精确地生成指标。

317 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

轻松、精确地生成指标。

Easy metrics

Easily create metrics for your application.

✨ Help support the maintenance of this package by sponsoring me.

Designed to work with Laravel, Filament, Easy enum, and more.

Supported metrics

  • Bar metric
  • Doughnut metric
  • Line metric
  • Pie metric
  • Polar metric
  • Trend metric
  • Value metric

Table of contents

  • Install
  • Usage
    • Value metric
    • Doughnut metric
    • Trend metric
    • Other metrics
  • Ranges
    • Available custom ranges
  • Growth rates
    • Using value metric
    • Using trend metric
    • Using doughnut metric
    • Available growth rate types
  • Tips
    • using getLabel
  • Practical examples
    • Filamentphp v3 widgets
  • Support the development
  • Credits
  • License

Install

composer require sakanjo/laravel-easy-metrics

Usage

Value metric

php
use SaKanjo\EasyMetrics\Metrics\Value;
use App\Models\User;

$data = Value::make(User::class)
    ->count();

Query types

The currently supported aggregate functions to calculate a given column compared to the previous time interval / range

Min
php
Value::make(User::class)
    ->min('age');
Max
php
Value::make(User::class)
    ->max('age');
Sum
php
Value::make(User::class)
    ->sum('age');
Average
php
Value::make(User::class)
    ->average('age');
Count
php
Value::make(User::class)
    ->count();

Doughnut metric

php
use SaKanjo\EasyMetrics\Metrics\Doughnut;
use App\Models\User;

[$labels, $data] = Doughnut::make(User::class)
    ->count('gender');

Query types

The currently supported aggregate functions to calculate a given column compared to the previous time interval / range

Min
php
Doughnut::make(User::class)
    ->min('age', 'gender');
Max
php
Doughnut::make(User::class)
    ->max('age', 'gender');
Sum
php
Doughnut::make(User::class)
    ->sum('age', 'gender');
Average
php
Doughnut::make(User::class)
    ->average('age', 'gender');
Count
php
Doughnut::make(User::class)
    ->count('gender');

Trend metric

php
use SaKanjo\EasyMetrics\Metrics\Trend;
use App\Models\User;

[$labels, $data] = Trend::make(User::class)
    ->countByMonths();

Query types

The currently supported aggregate functions to calculate a given column compared to the previous time interval / range

Min
php
$trend->minByYears('age'); 
$trend->minByMonths('age'); 
$trend->minByWeeks('age');  
$trend->minByDays('age');  
$trend->minByHours('age');  
$trend->minByMinutes('age');  
Max
php
$trend->maxByYears('age'); 
$trend->maxByMonths('age'); 
$trend->maxByWeeks('age');  
$trend->maxByDays('age');  
$trend->maxByHours('age');  
$trend->maxByMinutes('age');  
Sum
php
$trend->sumByYears('age'); 
$trend->sumByMonths('age'); 
$trend->sumByWeeks('age');  
$trend->sumByDays('age');  
$trend->sumByHours('age');  
$trend->sumByMinutes('age');  
Average
php
$trend->averageByYears('age'); 
$trend->averageByMonths('age'); 
$trend->averageByWeeks('age');  
$trend->averageByDays('age');  
$trend->averageByHours('age');  
$trend->averageByMinutes('age');  
Count
php
$trend->countByYears(); 
$trend->countByMonths(); 
$trend->countByWeeks();  
$trend->countByDays();  
$trend->countByHours();  
$trend->countByMinutes();  

Other metrics

  • Bar extends Trend
  • Line extends Trend
  • Doughnut extends Pie
  • Polar extends Pie

Ranges

Every metric class contains a ranges method, that will determine the range of the results based on it's date column.

php
use SaKanjo\EasyMetrics\Metrics\Trend;
use SaKanjo\EasyMetrics\Metrics\Enums\Range;
use App\Models\User;

Value::make(User::class)
    ->range(30)
    ->ranges([
        15, 30, 365,
        Range::TODAY, // Or 'TODAY'
    ]);

Available custom ranges

  • Range::TODAY
  • Range::YESTERDAY
  • Range::MTD
  • Range::QTD
  • Range::YTD
  • Range::ALL

Growth rates

Growth rate, expressed as both a value and a percentage, measures the change in a quantity over time, showing the speed of its expansion or contraction in both absolute and relative terms.

Using Value metric

php
use SaKanjo\EasyMetrics\Metrics\Value;
use SaKanjo\EasyMetrics\Enums\GrowthRateType;
use App\Models\User;

[$value, $growth] = Value::make(User::class)
    ->withGrowthRate()
    ->growthRateType(GrowthRateType::Value) // default is `Percentage`
    ->count();

Using Trend metric

php
use SaKanjo\EasyMetrics\Metrics\Trend;
use App\Models\User;

[$labels, $data, $growth] = Trend::make(User::class)
    ->withGrowthRate()
    ->countByYears();

Using Doughnut metric

php
use SaKanjo\EasyMetrics\Metrics\Doughnut;
use App\Models\User;

[$labels, $data, $growth] = Doughnut::make(User::class)
    ->withGrowthRate()
    ->count('gender');

Available growth rate types

  • GrowthRateType::Value
  • GrowthRateType::Percentage

Tips

Using getLabel

You can use the getLabel method to customize the retreived data labels, for example:

php
range($this->filter)
            ->rangesFromOptions($this->getFilters())
            ->countByMonths();

        return [
            'datasets' => [
                [
                    'label' => 'Users',
                    'data' => $data,
                ],
            ],
            'labels' => $labels,
        ];
    }

    protected function getType(): string
    {
        return 'line';
    }

    protected function getFilters(): ?array
    {
        return [
            15 => '15 Months',
            30 => '30 Months',
            60 => '60 Months',
        ];
    }
}

Support the development

Do you like this project? Support it by donating

Click the " Sponsor" at the top of this repo.

©️ Credits

  • Salah Kanjo
  • All Contributors

License

MIT License © 2023-PRESENT Salah Kanjo

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPchartslaravelmetricsreports

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架