Change the data type of the x-axis of a graph? PHP / Laravel 5.6

1

Good evening,

I'm using a tool for rapid development called QuickAdmin, I need render a graphic on the screen for the user who has a data of type x on the x axis and on the y axis a data of type time. The graph will look like this:

However,Quickadminonlyallowsmetoputdate/timedataonthexaxis,soIcanonlyputyearorhoursthereandnotthesectornameasitshould.ThisisgraphgeneratedbyQuickadmin:

Can not understand the logic to make this change in code, does anyone know what I should change in the Controller to get a data of type string in that x axis of the graph?

<?php
namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Treinamento;
use App\Turma;
use Carbon\Carbon; 

class ReportsController extends Controller
{
    public function horasTreinadasPorSetor(Request $request)
    {
         if ($request->has('date_filter')) { 
              $parts = explode(' - ' , $request->input('date_filter')); 
              $date_from = Carbon::createFromFormat(config('app.date_format'), $parts[0])->format('Y-m-d');
              $date_to = Carbon::createFromFormat(config('app.date_format'), $parts[1])->format('Y-m-d');
         } else { 
              $date_from = new Carbon('last Monday');
              $date_to = new Carbon('this Sunday');
         } 
        $reportTitle = 'Horas Treinadas por Setor';
        $reportLabel = 'AVG';
        $chartType   = 'bar';

        $results = Treinamento::where('created_at', '>=', $date_from)->where('created_at', '<=', $date_to)->get()->sortBy('created_at')->groupBy(function ($entry) {
            if ($entry->created_at instanceof \Carbon\Carbon) {
                return \Carbon\Carbon::parse($entry->created_at)->format('Y');
            }
            try {
               return \Carbon\Carbon::createFromFormat(config('app.date_format'), $entry->created_at)->format('Y');
            } catch (\Exception $e) {
                 return \Carbon\Carbon::createFromFormat(config('app.date_format') . ' H:i:s', $entry->created_at)->format('Y');
            }        })->map(function ($entries, $group) {
            return $entries->avg('id');
        });

        return view('admin.reports', compact('reportTitle', 'results', 'chartType', 'reportLabel'));
    }
    
asked by anonymous 08.12.2018 / 00:39

0 answers