From c39f00f80d05a07eaf5358da87b7bc1b03d7fa8c Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 28 Mar 2017 19:58:54 +0300 Subject: [PATCH] -Am charts ready --- backend/models/Analytics.php | 26 ++++++++++++++++++++------ backend/views/site/analytics.php | 94 ++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------- backend/views/site/stab.php | 26 ++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 56 deletions(-) create mode 100644 backend/views/site/stab.php diff --git a/backend/models/Analytics.php b/backend/models/Analytics.php index 08a1085..1025072 100644 --- a/backend/models/Analytics.php +++ b/backend/models/Analytics.php @@ -2,13 +2,21 @@ namespace backend\models; use yii\base\Model; - use yii\helpers\ArrayHelper; - use yii\helpers\VarDumper; + /** + * Class Analytics + * + * @package backend\models + */ class Analytics extends Model { public $viewId; - + + /** + * Preparing and querying data + * + * @return \Google_Service_AnalyticsReporting_GetReportsResponse + */ private function executeQuery() { $client = new \Google_Client(); @@ -104,7 +112,12 @@ return $response; } - + + /** + * Generates data for view + * + * @return array + */ public function generateData() { $reports = $this->executeQuery(); @@ -134,7 +147,7 @@ $dimensions = $row->getDimensions(); for ($i = 0; $i < count($dimensionHeaders) && $i < count($dimensions); $i++) { - $data[ 'plot' ][ $rowIndex ][ 'day' ] = $dimensions[ $i ]; + $data[ 'plot' ][ $rowIndex ][ 'day' ] = date('d-m-Y', strtotime($dimensions[ $i ])); } $metrics = $row->getMetrics(); @@ -155,7 +168,8 @@ } /** - * Generating data for + * Generating data for tabs, + * with browser, city and country statistics */ $data2 = []; diff --git a/backend/views/site/analytics.php b/backend/views/site/analytics.php index 1252a04..e2e1723 100644 --- a/backend/views/site/analytics.php +++ b/backend/views/site/analytics.php @@ -8,7 +8,7 @@ */ use artbox\gentelella\widgets\XPanel; - use dosamigos\highcharts\HighCharts; + use speixoto\amcharts\Widget; use yii\bootstrap\Tabs; use yii\web\View; @@ -71,6 +71,9 @@ 'type' => 'serial', 'dataProvider' => $data[ 'plot' ], 'categoryField' => 'day', + 'categoryAxis' => [ + 'labelFrequency' => 5, + ], 'graphs' => [ [ "balloon" => [ @@ -87,8 +90,8 @@ "title" => "red line", "useLineColorForBulletBorder" => true, "valueField" => "users", - "balloonText" => "[[users]]", - "lineColors" => '#9ABCC3', + "balloonText" => "Users: [[users]]", + "lineColor" => '#9ABCC3', ], [ "balloon" => [ @@ -105,13 +108,23 @@ "title" => "red line", "useLineColorForBulletBorder" => true, "valueField" => "sessions", - "balloonText" => "[[sessions]]", - "lineColors" => '#A8E3D6', + "balloonText" => "Sessions: [[sessions]]", + "lineColor" => '#A8E3D6', ], ], + 'chartCursor' => [ + "pan" => true, + "valueLineEnabled" => true, + "valueLineBalloonEnabled" => true, + "cursorAlpha" => 1, + "cursorColor" => "#1ABB9C", + "limitToGraph" => "g1", + "valueLineAlpha" => 0.2, + "valueZoomable" => true, + ], ]; - echo speixoto\amcharts\Widget::widget( + echo Widget::widget( [ 'chartConfiguration' => $chartConfiguration, 'width' => '100%', @@ -134,50 +147,30 @@ ); ?> [ - 'exporting' => [ - 'enabled' => false, - ], - 'colors' => [ - '#9ABCC3', - '#A8E3D6', - ], - 'chart' => [ - 'plotBackgroundColor' => null, - 'plotBorderWidth' => null, - 'plotShadow' => false, - 'type' => 'pie', - ], - 'title' => [ - 'text' => 'Analytics', - ], - 'series' => [ - [ - 'name' => 'Sessions', - 'data' => [ - [ - 'name' => 'New visitor', - 'y' => round(intval($data[ 'new' ]), 2), - ], - [ - 'name' => 'Returning Visitor', - 'y' => 100 - round(intval($data[ 'new' ]), 2), - ], - ], - ], - ], - 'credits' => [ - 'enabled' => false, - ], - 'plotOptions' => [ - 'pie' => [ - 'allowPointSelect' => true, - 'cursor' => 'pointer', - ], - ], + $chartConfiguration = [ + "type" => "pie", + "titleField" => "category", + "valueField" => "column-1", + "dataProvider" => [ + [ + "category" => "New Visitor", + "column-1" => round(intval($data[ 'new' ]), 2), ], + [ + "category" => "Returning Visitor", + "column-1" => 100 - round(intval($data[ 'new' ]), 2), + ], + ], + "colors" => [ + "#A8E3D6", + "#9ABCC3", + ], + ]; + + echo Widget::widget( + [ + 'chartConfiguration' => $chartConfiguration, + 'width' => '100%', ] ); ?> @@ -239,4 +232,5 @@ - \ No newline at end of file + + diff --git a/backend/views/site/stab.php b/backend/views/site/stab.php new file mode 100644 index 0000000..d0a42d4 --- /dev/null +++ b/backend/views/site/stab.php @@ -0,0 +1,26 @@ +registerJs($js, View::POS_READY); +?> + +
+ -- libgit2 0.21.4