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/ */
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]);
}
}
$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');
// 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'));
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
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.