ConsoleTV Chartjs chart type

Posted 5 months ago by kshitizmittal

I am using this below package for charts.

// CHARTS
ConsoleTVs\Charts\ChartsServiceProvider::class,

This is the class I made for charts,

<?php

namespace App\Charts;

use ConsoleTVs\Charts\Classes\Chartjs\Chart;

class UserChart extends Chart
{
    /**
     * Initializes the chart.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }
}

This is how I made object in controller,

    public function index()
    {
        $departments=Department::where(['deptstatus'=>'on'])->get();
        $designations=Designation::where(['degstatus'=>'on'])->get();
        $officelocations=Officelocation::where(['locstatus'=>'on'])->get();
        $users = Employeedetail::with(['officelocations','departments','designations','subdepartments'])->where(['status'=>'Active'])->get();

        $graphData = DB::select("SELECT result.childdepartment as label, count(result.id) as value from (select ed.id, ed.emp_id, dept.parentdepartment, dept.childdepartment from employeedetails as ed LEFT JOIN (select child_dept.deptid as id, child_dept.deptname as childdepartment, parent_dept.deptname as parentdepartment from departments as parent_dept INNER JOIN departments as child_dept on child_dept.deptparent = parent_dept.deptid) as dept on ed.department = dept.id) as result GROUP BY childdepartment");

        $chart = new UserChart;
        
        $chart->labels(['One', 'Two', 'Three', 'Four']);
        $chart->dataset('My dataset', 'line', [1, 2, 3, 4]);
        $chart->dataset('My dataset 2', 'doughnut', [4, 3, 2, 1]);
        $chart->options([
            'tooltip' => [
                'show' => true // or false, depending on what you want.
            ]
        ]);

        return view('eno.user',compact('users','departments','designations','officelocations','graphData','chart'));
    }

My concern is how I can change the chart type ??

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