pavlm / yii2-stats-widget
Statistics widget for exploring time series data from diffrent sources of your application
Installs: 49
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 3
Open Issues: 0
Type:yii2-extension
Requires
- php: >=5.5
- bower-asset/chartjs: *
Requires (Dev)
- yiisoft/yii2: ^2.0
This package is auto-updated.
Last update: 2025-04-29 00:36:49 UTC
README
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.
Localization
'i18n' => [ 'translations' => [ 'stats-widget' => [ 'class' => yii\i18n\PhpMessageSource::class, 'basePath' => '@pavlm/yii/stats/messages', ], ], ],