Laravel 5.6 - Generate Free Charts and Graphs Example

Here, i will let you know how to generate charts in laravel 5.6 application using consoletvs charts package. i will create line chart, geo chart, bar chart, pie chart, donut chart, line chart and area chart example in laravel. you can also create gauge chart, progressbar chart, areaspline chart, scatter chart, percentage chart etc using consoletvs charts composer package.

In this tutorial i just install consoletvs charts composer package and create one route with parameter. parameter is a chart name and then in controller i just create one method and write code for chart.

So, you have to just follow bellow few step and you will get all charts example, so let's see bellow example:

Step 1: Install ConsoleTVs Package

first of all we will install ConsoleTVs/Charts composer package by following composer command in your laravel 5.6 application.

composer require consoletvs/charts

After successfully install package, open config/app.php file and add service provider and alias.


'providers' => [




'aliases' => [


'Charts' => ConsoleTVs\Charts\Facades\Charts::class,


Step 2: Create Users Dummy Records

you have users table by running default migrations of laravel. So we have to generate dummy records for demo in users table. So let's run bellow command and get dummy records.

php artisan tinker

>>> factory(App\User::class, 20)->create();

Step 3: Add Routes

Now we will add routes for demo example, so simply add following route in your route file:



Step 4: Add New Controller

Here,we require to create new controller ChartController that will manage index method of route. So let's put bellow code.



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Charts;

use App\User;

use DB;

class ChartController extends Controller



* Show the application dashboard.


* @return \Illuminate\Http\Response


public function makeChart($type)


switch ($type) {

case 'bar':

$users = User::where(DB::raw("(DATE_FORMAT(created_at,'%Y'))"),date('Y'))


$chart = Charts::database($users, 'bar', 'highcharts')

->title("Monthly new Register Users")

->elementLabel("Total Users")

->dimensions(1000, 500)


->groupByMonth(date('Y'), true);


case 'pie':

$chart = Charts::create('pie', 'highcharts')

->title(' Laravel Pie Chart')

->labels(['Codeigniter', 'Laravel', 'PHP'])





case 'donut':

$chart = Charts::create('donut', 'highcharts')

->title(' Laravel Donut Chart')

->labels(['First', 'Second', 'Third'])





case 'line':

$chart = Charts::create('line', 'highcharts')

->title(' Laravel Line Chart')

->elementLabel(' Laravel Line Chart Lable')

->labels(['First', 'Second', 'Third'])





case 'area':

$chart = Charts::create('area', 'highcharts')

->title(' Laravel Area Chart')

->elementLabel(' Laravel Line Chart label')

->labels(['First', 'Second', 'Third'])





case 'geo':

$chart = Charts::create('geo', 'highcharts')

->title(' Laravel GEO Chart')

->elementLabel(' Laravel GEO Chart label')

->labels(['ES', 'FR', 'RU'])

->colors(['#3D3D3D', '#985689'])






# code...



return view('chart', compact('chart'));



Step 5: Create Blade File

At last we require to create blade file call chart.blade.php, will bootstrap layout. So let's add bellow code:


<!DOCTYPE html>

<html lang="en">


<meta charset="utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>My Charts</title>

{!! Charts::styles() !!}



<!-- Main Application (Can be VueJS or other JS framework) -->

<div class="app">


{!! $chart->html() !!}



<!-- End Of Main Application -->

{!! Charts::scripts() !!}

{!! $chart->script() !!}



Now, finally we are ready to run this example. So you can run and check on following path:







I hope you found your best.

March 19, 2018 | 3135 Viewer | Category : PHP Laravel Laravel 5.6
Related Posts