Aronaman
6 months ago
404
0
Laravel

load chart

Posted 6 months ago by Aronaman

Controller

 $apiDay = url('admin/ajax-day-statics');        
        $apiMonth = url('admin/ajax-month-statics');
        $apiYear = url('admin/ajax-year-statics');

 $toDayStatics = new GoogleAnalytics;
         if(route('ajax.day.statics')){
             $toDayStatics->labels(['Today'])->load($apiDay);
         }elseif(route('ajax.month.statics')){
             $toDayStatics->labels(['This Month'])->load($apiMonth);
         }elseif(route('ajax.year.statics')){
            $toDayStatics->labels(['This Year'])->load($apiYear);
         }

// google Analytics Daily
    public function ajaxDayStatics(Request $request)
    {
        $day = Analytics::performQuery(Period::days(1),
        'ga:',
        [
            'metrics' => 'ga:users,ga:newUsers,ga:sessions,ga:sessionsPerUser,ga:pageviews,ga:pageviewsPerSession,ga:avgSessionDuration,ga:bounceRate',

        ]);

        $todayUsersVisits=$day->totalsForAllResults['ga:users'];
        $todaySessisons=$day->totalsForAllResults['ga:sessions'];

    // dd($thisMonth->totalsForAllResults['ga:bounceRate']);
   

         $toDayStatics = new GoogleAnalytics;
         // $toDayStatics->labels(['Today']);
         $toDayStatics->dataset('Visits', 'bar',[$todayUsersVisits])->color('#7cbd1e')->backgroundcolor("#7cbd1e");


          return $toDayStatics->apiDay();

    }

Html

 <div class="btn-group btn-group-toggle float-right mr-3" data-toggle="buttons">
     <label class="btn btn-outline-secondary active">
       <input id="day" type="radio" name="options" autocomplete="off" checked=""> Day
    </label>
    <label class="btn btn-outline-secondary ">
       <input id="month" type="radio" name="options" autocomplete="off" > Month
    </label>
    <label class="btn btn-outline-secondary">
      <input id="year" type="radio" name="options" autocomplete="off"> Year
    </label>
     </div>

<div class="c-chart-wrapper" style="height:300px;margin-top:40px;">

    {!! $toDayStatics->container() !!}
 </div>

Ajax

@if($toDayStatics)
       {!! $toDayStatics->script() !!}
 @endif


     <script type="text/javascript">
        
        $("#day").change(function(){
          var original_apiDay_url = {{ $toDayStatics->id }}_api_url;
            
            {{ $toDayStatics->id }}_refresh(original_apiDay_url );
        });

        $("#month").change(function(){
          var original_apiMonth_url = {{ route('ajax.month.statics') }};
            
            {{ $toDayStatics->id }}_refresh(original_apiMonth_url );
        });
        $("#year").change(function(){
          var original_apiYear_url = {{ route('ajax.year.statics') }};
            
            {{ $toDayStatics->id }}_refresh(original_apiYear_url);
        });
    </script>

i am using ConsoleTvs Charts package i am try to load chart based on month, year and day. how can i do this??

i am new to this i dont know how to load ajax in console tvs chart pakage

any help thanks

Please sign in or create an account to participate in this conversation.