Blame view

backend/web/js/analytics.js 4.98 KB
c237629a   Anastasia   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
  $(
      function() {
          $.ajax(
              {
                  url: "/admin/ajax/analytics",
                  type: "POST",
                  success: function(data) {
                      // Replacing top data
                      $('#sessions')
                          .animateNumber({number: data.sessions}, 2000);
                      $('#users')
                          .animateNumber({number: data.users}, 2000);
                      $('#views')
                          .animateNumber({number: data.views}, 2000);
                      $('#newusers')
                          .animateNumber({number: data.newusers}, 2000);
                      // Building main chart
                      var chart = AmCharts.makeChart(
                          "chartdiv", {
                              "type": "serial",
                              "startDuration": 1,
                              "startEffect": "elastic",
                              'dataProvider': data.plot,
                              'categoryField': 'day',
                              'categoryAxis': {
                                  'labelFrequency': 5
                              },
                              'graphs': [
                                  {
                                      'balloon': {
                                          "drop": true,
                                          "adjustBorderColor": false,
                                          "color": "#ffffff"
                                      },
                                      "bullet": "round",
                                      "bulletBorderAlpha": 1,
                                      "bulletColor": "#FFFFFF",
                                      "bulletSize": 5,
                                      "hideBulletsCount": 50,
                                      "lineThickness": 2,
                                      "title": "red line",
                                      "useLineColorForBulletBorder": true,
                                      "valueField": "users",
                                      "balloonText": "<span style='font-size:18px;'>Users: [[users]]</span>",
                                      "lineColor": '#ff8800'
                                  },
                                  {
                                      'balloon': {
                                          "drop": true,
                                          "adjustBorderColor": false,
                                          "color": "#ffffff"
                                      },
                                      "bullet": "round",
                                      "bulletBorderAlpha": 1,
                                      "bulletColor": "#FFFFFF",
                                      "bulletSize": 5,
                                      "hideBulletsCount": 50,
                                      "lineThickness": 2,
                                      "title": "red line",
                                      "useLineColorForBulletBorder": true,
                                      "valueField": "sessions",
                                      "balloonText": "<span style='font-size:18px;'>Sessions: [[sessions]]</span>",
                                      "lineColor": '#652e8f'
                                  }
                              ],
                              'chartCursor': {
                                  "pan": true,
                                  "valueLineEnabled": true,
                                  "valueLineBalloonEnabled": true,
                                  "cursorAlpha": 1,
                                  "cursorColor": "#46b749",
                                  "limitToGraph": "g1",
                                  "valueLineAlpha": 0.2,
                                  "valueZoomable": true,
  
                              }
                          }
                      );
  
                      // Building pie chart
                      var pie = AmCharts.makeChart(
                          "piediv", {
                              "radius": 130,
                              "balloonText": "[[title]]<br><span style='font-size:14px'><b>[[value]]</b> ([[percents]]%)</span>",
                              "type": "pie",
                              "color": "#fff",
                              "labelsEnabled" : false,
                              'dataProvider': data.pie,
                              "titleField": "category",
                              "valueField": "column-1",
                              'colors': [
                                  "#652e8f",
                                  "#ff8800"
                              ]
                          }
                      );
                      // Replacing table stabs
                      $('#browsers')
                          .replaceWith(data.browsers);
                      $('#cities')
                          .replaceWith(data.cityes);
                      $('#countries')
                          .replaceWith(data.countries);
                      $('.yt-loader')
                          .remove();
                  }
              }
          )
      }
  );