PHP code example of githubconsoletvs / charts5yes

1. Go to this page and download the library: Download githubconsoletvs/charts5yes library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

githubconsoletvs / charts5yes example snippets


ConsoleTVs\Charts\ChartsServiceProvider::class,

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



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use Charts;

class TestController extends Controller
{
    public function index()
    {
        $chart = Charts::multi('bar', 'material')
            // Setup the chart settings
            ->title("My Cool Chart")
            // A dimension of 0 means it will take 100% of the space
            ->dimensions(0, 400) // Width x Height
            // This defines a preset of colors already done:)
            ->template("material")
            // You could always set them manually
            // ->colors(['#2196F3', '#F44336', '#FFC107'])
            // Setup the diferent datasets (this is a multi chart)
            ->dataset('Element 1', [5,20,100])
            ->dataset('Element 2', [15,30,80])
            ->dataset('Element 3', [25,10,40])
            // Setup what the values mean
            ->labels(['One', 'Two', 'Three']);

        return view('test', ['chart' => $chart]);
    }
}

Charts::create('line', 'highcharts')
    ->title('My nice chart')
    ->labels(['First', 'Second', 'Third'])
    ->values([5,10,20])
    ->dimensions(0,500);

Charts::multi('line', 'highcharts')
    ->colors(['#ff0000', '#00ff00', '#0000ff'])
    ->labels(['One', 'Two', 'Three'])
    ->dataset('Test 1', [1,2,3])
    ->dataset('Test 2', [0,6,0])
    ->dataset('Test 3', [3,4,1]);

        Charts::multi('bar', 'minimalist')
                    ->responsive(false)
                    ->dimensions(0, 500)
                    ->colors(['#ff0000', '#00ff00', '#0000ff'])
                    ->labels(['One', 'Two', 'Three'])
                    ->dataset('Test 1', [1,2,3])
                    ->dataset('Test 2', [0,6,0])
                    ->dataset('Test 3', [3,4,1]);
    

$chart = Charts::database(User::all(), 'bar', 'highcharts');

    $chart = Charts::database(User::all(), 'bar', 'highcharts')->data(Role::all());
    

    $chart = Charts::database(User::all(), 'bar', 'highcharts')->dateColumn('my_date_column');
    

    $chart = Charts::database(User::all(), 'bar', 'highcharts')->dateFormat('j F y');
    

    $chart = Charts::database(User::all(), 'bar', 'highcharts')->monthFormat('F Y');
    

    $chart = Charts::database(User::all(), 'bar', 'highcharts')->hourFormat('j, g A');
    

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Charts;
use App\User;
use DB;

class ChartController extends Controller
{
    public function index()
    {
    	$users = User::where(DB::raw("(DATE_FORMAT(created_at,'%Y'))"),date('Y'))
    				->get();
        $chart = Charts::database($users, 'bar', 'highcharts')
			      ->title("Monthly new Register Users")
			      ->elementLabel("Total Users")
			      ->dimensions(1000, 500)
			      ->responsive(false)
			      ->groupByMonth(date('Y'), true);
        return view('chart',compact('chart'));
    }
}

        
    $chart = Charts::database(User::all(), 'bar', 'highcharts')
        ->elementLabel("Total")
        ->dimensions(1000, 500)
        ->responsive(false)
        ->groupBy('game');
    

        $chart = Charts::database(User::all(), 'pie', 'highcharts')
            ->title('User types')
            ->dimensions(1000, 500)
            ->responsive(false)
            ->groupBy('type', null, [1 => 'Admins', 2 => 'Users', 3 => 'Trainees']);
    

    $chart = Charts::database(User::all(), 'bar', 'highcharts')
        ->elementLabel("Total")
        ->dimensions(1000, 500)
        ->responsive(false)
        ->groupByYear();

    // to display a number of years behind, pass a int parameter. For example to display the last 10 years:
    $chart = Charts::database(User::all(), 'bar', 'highcharts')
        ->elementLabel("Total")
        ->dimensions(1000, 500)
        ->responsive(false)
        ->groupByYear(10);
    

    $chart = Charts::database(User::all(), 'bar', 'highcharts')
        ->elementLabel("Total")
        ->dimensions(1000, 500)
        ->responsive(false)
        ->groupByMonth();

    // to display a specific year, pass the parameter. For example to display the months of 2016 and display a fancy output label:
    $chart = Charts::database(User::all(), 'bar', 'highcharts')
        ->elementLabel("Total")
        ->dimensions(1000, 500)
        ->responsive(false)
        ->groupByMonth('2016', true);
    

    $chart = Charts::database(User::all(), 'bar', 'highcharts')
        ->elementLabel("Total")
        ->dimensions(1000, 500)
        ->responsive(false)
        ->groupByDay();

    // to display a specific month and/or year, pass the parameters. For example to display the days of september 2016 and display a fancy output label:
    $chart = Charts::database(User::all(), 'bar', 'highcharts')
        ->elementLabel("Total")
        ->dimensions(1000, 500)
        ->responsive(false)
        ->groupByDay('09', '2016', true);
    

    $chart = Charts::database(User::all(), 'bar', 'highcharts')
        ->elementLabel("Total")
        ->dimensions(1000, 500)
        ->responsive(false)
        ->groupByHour()

    // to display a specific day and/or month and/or year, pass the parameters. For example to display the hours of May 12, 2017, and display a fancy output label:
    $chart = Charts::database(User::all(), 'bar', 'highcharts')
        ->elementLabel("Total")
        ->dimensions(1000, 500)
        ->responsive(false)
        ->groupByHour('12', '05', '2017', true)
    

    $chart = Charts::database(User::all(), 'bar', 'highcharts')
        ->elementLabel("Total")
        ->dimensions(1000, 500)
        ->responsive(false)
        ->lastByYear();

    // to display a number of years behind, pass a int parameter. For example to display the last 3 years:
    $chart = Charts::database(User::all(), 'bar', 'highcharts')
        ->elementLabel("Total")
        ->dimensions(1000, 500)
        ->responsive(false)
        ->lastByYear(3);
    

    $chart = Charts::database(User::all(), 'bar', 'highcharts')
        ->elementLabel("Total")
        ->dimensions(1000, 500)
        ->responsive(false)
        ->lastByMonth();

    // to display a number of months behind, pass a int parameter. For example to display the last 6 months and use a fancy output:
    $chart = Charts::database(User::all(), 'bar', 'highcharts')
        ->elementLabel("Total")
        ->dimensions(1000, 500)
        ->responsive(false)
        ->lastByMonth(6, true);
    

    $chart = Charts::database(User::all(), 'bar', 'highcharts')
        ->elementLabel("Total")
        ->dimensions(1000, 500)
        ->responsive(false)
        ->lastByDay();

    // to display a number of days behind, pass a int parameter. For example to display the last 14 days and use a fancy output:
    $chart = Charts::database(User::all(), 'bar', 'highcharts')
        ->elementLabel("Total")
        ->dimensions(1000, 500)
        ->responsive(false)
        ->lastByDay(14, true);
    

    $data = Orders::select('orders.created_at', DB::raw('count(orders.id) as aggregate'))->groupBy(DB::raw('Date(orders.created_at)'))->get(); //must alias the aggregate column as aggregate

    $chart = Charts::database($data)->preaggregated(true)->lastByDay(7, false);
    

    $chart = new Database(BankRecord::all(), 'bar', 'highcharts');
    $chart->aggregateColumn('amount', 'sum');
    

Charts::multiDatabase('line', 'material')
    ->dataset('Element 1', Users::all())
    ->dataset('Element 2', Posts::all());

Charts::multiDatabase('line', 'material')
    ->dataset('Element 1', Users::all())
    ->dataset('Element 2', Posts::all())
    ->groupByMonth(2017, true);

$chart = Charts::realtime(url('/path/to/json'), 2000, 'gauge', 'google')
            ->values([65, 0, 100])
            ->labels(['First', 'Second', 'Third'])
            ->responsive(false)
            ->height(300)
            ->width(0)
            ->title("Permissions Chart")
            ->valueName('value'); //This determines the json index for the value

    $chart = Charts::realtime(url('/path/to/json'), 2000, 'gauge', 'google')
                ->values([65, 0, 100])
                ->labels(['First', 'Second', 'Third'])
                ->responsive(false)
                ->height(300)
                ->width(0)
                ->title("Permissions Chart")
                ->valueName('value'); //This determines the json index for the value
    

    $chart = Charts::realtime(url('/path/to/json'), 2000, 'gauge', 'google')
                ->values([65, 0, 100])
                ->labels(['First', 'Second', 'Third'])
                ->responsive(false)
                ->height(300)
                ->width(0)
                ->title("Permissions Chart")
                ->url(url('/new/json'));
    

    $chart = Charts::realtime(url('/path/to/json'), 2000, 'gauge', 'google')
                ->values([65, 0, 100])
                ->labels(['First', 'Second', 'Third'])
                ->responsive(false)
                ->height(300)
                ->width(0)
                ->title("Permissions Chart")
                ->interval(3000); // in ms
    

    $chart = Charts::realtime(url('/path/to/json'), 1000, 'area', 'highcharts')
                ->responsive(false)
                ->height(300)
                ->width(0)
                ->title("Permissions Chart")
                ->maxValues(10);
    

Charts::math('sin(x)', [0, 10], 0.2, 'line', 'highcharts');

  Charts::math('sin(x)', [0, 10], 0.2, 'line', 'highcharts')->mathFunction('x+1');
  

    Charts::math('sin(x)', [0, 10], 0.2, 'line', 'highcharts')->interval([2, 8]);
    

    Charts::math('sin(x)', [0, 10], 0.2, 'line', 'highcharts')->amplitude(0.5);
    

    Charts::math('sin(x)', [0, 10], 0.2, 'line', 'highcharts')->calculate();
    

Charts::url(url('/api/data-url'), 'line', 'highcharts');

    $values_name = 'values2';
    

    $labels_name = 'labels2';
    

  Charts::create('line');
  Charts::create('line', 'highcharts');
  

    Charts::database(User::all());
    Charts::create(User::all(), 'line', 'highcharts');
    

    Charts::realtime(url('/json/data'), 2000, 'gauge', 'google')
    

    Charts::math('sin(x)', [0, 10], 0.2, 'line', 'highcharts');
    

    Charts::multi('line', 'material');
    

    Charts::multi('line', 'material');
    

     echo Charts::assets(); 

    // All libraries
    {!! Charts::styles() !!}
    // Only certain libraries
    {!! Charts::styles(['google', 'material']) !!}
    

    // All libraries
    {!! Charts::styles() !!}
    // Only certain libraries
    {!! Charts::styles(['google', 'material']) !!}
    

  // Return all the libraries available
  print_r(Charts::libraries());

  // Return all the libraries available for the line chart
  print_r(Charts::libraries('line'));
  

  // Return all the chart types available
  print_r(Charts::types());

  // Return all the chart types available for the highcharts library
  print_r(Charts::types('highcharts'));
  

    Charts::create('line', 'highcharts')->loader(false);
    

    Charts::create('line', 'highcharts')->loader(true)->loaderDuration(2000);
    

    Charts::create('line', 'highcharts')->loader(true)->loaderColor('#FF0000');
    

    Charts::create('line', 'highcharts')->backgroundColor('#FF0000');
    

    Charts::create('line', 'highcharts')->template('material');
    

    Charts::create('line', 'highcharts')->oneColor(true);
    

    Charts::create('line', 'highcharts')->credits(false);
    

    Charts::create('line', 'google')->container('my-division-id');
    

    Charts::create('line', 'google')->view('my.view');
    

    Charts::create('geo', 'google')->region('FR');
    

    Charts::create('gauge', 'google')->gaugeStyle('right');
    

  Charts::create('line', 'highcharts')->type('pie');
  

  Charts::create('line', 'highcharts')->library('google');
  

  Charts::create('line', 'highcharts')->labels(['First', 'Second', 'Third']);
  

  Charts::create('line', 'highcharts')->values([10, 50, 100]);
  

  Charts::create('line', 'highcharts')->elementLabel('Total Views');
  

  Charts::create('line', 'highcharts')->title('My Chart');
  

  Charts::create('line', 'highcharts')->colors(['#ff0000', '#00ff00', '#0000ff']);
  

  Charts::create('line', 'highcharts')->width(1000);
  

  Charts::create('line', 'highcharts')->height(500);
  

  Charts::create('line', 'highcharts')->height(1000, 500);
  

  Charts::create('line', 'highcharts')->responsive(false);
  

  Charts::create('line', 'highcharts')->legend(false);
  

  Charts::create('line', 'highcharts')->x_axis_title('Year');
  

  Charts::create('line', 'highcharts')->y_axis_title('Number of Units');
  

  Charts::database(User::all(), 'line', 'highcharts')->language('es');
  

  print_r(Charts::create('line', 'highcharts')->settings());
  

  echo Charts::create('line', 'highcharts')->labels(['One', 'Two'])->values([10, 20])->render();
  

  Charts::create('pie', 'highcharts')
    ->title('My nice chart')
    ->labels(['First', 'Second', 'Third'])
    ->values([5,10,20])
    ->dimensions(1000,500)
    ->responsive(false);
  

  Charts::create('donut', 'highcharts')
    ->title('My nice chart')
    ->labels(['First', 'Second', 'Third'])
    ->values([5,10,20])
    ->dimensions(1000,500)
    ->responsive(false);
  

  Charts::create('line', 'highcharts')
    ->title('My nice chart')
    ->elementLabel('My nice label')
    ->labels(['First', 'Second', 'Third'])
    ->values([5,10,20])
    ->dimensions(1000,500)
    ->responsive(false);
  

  Charts::create('area', 'highcharts')
    ->title('My nice chart')
    ->elementLabel('My nice label')
    ->labels(['First', 'Second', 'Third'])
    ->values([5,10,20])
    ->dimensions(1000,500)
    ->responsive(false);
  

  Charts::multi('areaspline', 'highcharts')
    ->title('My nice chart')
    ->colors(['#ff0000', '#ffffff'])
    ->labels(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday','Saturday', 'Sunday'])
    ->dataset('John', [3, 4, 3, 5, 4, 10, 12])
    ->dataset('Jane',  [1, 3, 4, 3, 3, 5, 4]);
   

  Charts::create('bar', 'highcharts')
    ->title('My nice chart')
    ->elementLabel('My nice label')
    ->labels(['First', 'Second', 'Third'])
    ->values([5,10,20])
    ->dimensions(1000,500)
    ->responsive(false);
  

  Charts::create('geo', 'highcharts')
    ->title('My nice chart')
    ->elementLabel('My nice label')
    ->labels(['ES', 'FR', 'RU'])
    ->colors(['#C5CAE9', '#283593'])
    ->values([5,10,20])
    ->dimensions(1000,500)
    ->responsive(false);
  

  Charts::create('gauge', 'canvas-gauges')
    ->title('My nice chart')
    ->elementLabel('My nice label')
    ->values([65,0,100])
    ->responsive(false)
    ->height(300)
    ->width(0);
  

  Charts::create('temp', 'canvas-gauges')
    ->title('My nice chart')
    ->elementLabel('My nice label')
    ->values([65,0,100])
    ->responsive(false)
    ->height(300)
    ->width(0);
  

  Charts::create('percentage', 'justgage')
    ->title('My nice chart')
    ->elementLabel('My nice label')
    ->values([65,0,100])
    ->responsive(false)
    ->height(300)
    ->width(0);
  

  Charts::create('progressbar', 'progressbarjs')
    ->values([65,0,100])
    ->responsive(false)
    ->height(50)
    ->width(0);
  

  Charts::multi('line', 'highcharts')->credits(false);
  

$chart = Charts::create('line', 'mylib');
config/app.php
config/app.php

php artisan vendor:publish
config/charts.php

$data = Shopping::all();
$chart = Charts::create('bar', 'highcharts')
             ->title('My nice chart')
             ->elementLabel('My nice label')
             ->labels($data->pluck('shoppingDate'))
             ->values($data->pluck('price'))
             ->responsive(true);
valueName($string)
config/charts.php
layoyts/charts.blade.php
latest_users.blade.php
routes/web.php

    

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;
    use Auth;

    class ChartsController extends Controller
    {
        /* Charts that will be protected to normal users */
        public $protected_charts = ['admin_dashboard'];

        /**
         * Show the chart, made to be displayed in an iframe.
         *
         * @param int $name
         * @param int $height
         */
        public function show($name, $height)
        {
            if (in_array($name, $this->protected_charts)) {
                $this->checkProtected();
            }
            return view("charts.$name", ['height' => $height]);
        }

        /**
         * Protected charts will go here first.
         * You can change this condition how you like.
         */
        public function checkProtected()
        {
            if(!Auth::user()->admin) {
                abort(404);
            }
        }
    }

    
library.type.php
mylib.line.php