Quexer69 / yii2-stats-widget

Statistics widget for exploring time series data from diffrent sources of your application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

yii2-stats-widget

Visualizes time series data from your application. Package consists of two parts.

  • Interactive stats widget based on charts.js library. Widget features are: different date ranges browsing, changing data group interval.
  • Data providers and formatters wich read and adapt data of your application for the stats widget.

Installation

composer require pavlm/yii2-stats-widget

Usage

1. Setup StatsAction

Add action to some controller. Configure time series provider.

    public function actions()
    {
        return [
            'stats-users' => [
                'class' => StatsAction::class,
                'providerFactory' => new TimeSeriesProviderCallbackFactory(function ($rangeStart, $rangeEnd, $period, $timeZone) {
                    return new QueryStatsProvider([
                        'rangeStart' => $rangeStart,
                        'rangeEnd' => $rangeEnd,
                        'period' => $period,
                        'timeZone' => $timeZone,
                        'timeZoneConnection' => new \DateTimeZone('Europe/Moscow'),
                        'query' => (new Query())->from('user'),
                        'dateField' => 'created_at',
                        'dateFieldType' => QueryStatsProvider::DATETYPE_INT,
                    ]);
                }),
                'timeZone' => 'Europe/Moscow',
                'defaultRange' => 'P2Y',
                'defaultPeriod' => 'P1Y',
            ],
        ];
    }

Note: additional time series provider(s) can be found in the pavlm/yii2-stats-providers package.

2. Add widget to a some application view.

Widget statsAction must be set to the action route configured in step 1.

echo StatsWidget::widget([
    'statsAction' => ['stats/stats-users'],
]);

3. Open page with stats widget.

StatsWidget example

Localization

    'i18n' => [
        'translations' => [
            'stats-widget' => [
                'class' => yii\i18n\PhpMessageSource::class,
                'basePath' => '@pavlm/yii/stats/messages',
            ],
        ],
    ],

About

Statistics widget for exploring time series data from diffrent sources of your application

License:MIT License


Languages

Language:PHP 91.0%Language:JavaScript 8.9%Language:Shell 0.1%