lavacharts
lavacharts copied to clipboard
Stucked with adding multiple charts in to single dashboard
I am using laravel 5.4 and i have created some charts using lava charts. And now i just need to add charts in to a single dashboard.
Issue
but here I am been stuck.
Controller Code (chart creation code)
this is my controller code
<?php
namespace app\Http\Controllers;
use Illuminate\Http\Request;
use Khill\Lavacharts\Lavacharts;
use app\expense;
use app\geocharttest;
class DashboardController extends Controller
{
public function barChart()
{
$lava = new Lavacharts;
$expenses = $lava->DataTable();
//return DB::table('expenses')->get();
$year=expense::select('year as 0', 'expense as 1')
->get()
->toArray();
$expenses->addStringColumn('expense')
->addNumberColumn('expense')
->addRows($year);
$lava->BarChart('expense', $expenses);
return view('Dashboard',compact('lava'));
}
public function geoChart()
{
$lava2 = new Lavacharts;
$fans = $lava2->DataTable();
//return DB::table('geocharttest')->get();
$value=geoCharttest::select('country as 0', 'count as 1')
->get()
->toArray();
$fans->addStringColumn('country')
->addNumberColumn('count')
->addRows($value);
$lava2->GeoChart('count', $fans);
return view('Dashboard',compact('lava2'));
}
}
View Code
<!-- geochart.blade.php -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Laravel GeoChart Example</title>
<link rel="stylesheet" href="{{asset('css/app.css')}}">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="row">
<div class="col-sm-12">
<div class="Card">
<h2>Laravel GeoChart Example</h2>
<div id="geo"></div>
<?= $lava2->render('GeoChart', 'count', 'geo') ?>
</div>
</div>
<div class="col-sm-12">
<div class="Card">
<h2>Laravel BarChart Example</h2><br/>
<div id="bar"></div>
<?= $lava->render('BarChart', 'expense', 'bar') ?>
</div>
</div>
</div>
</body>
</html>
I've answered this a few times around some of the closed issues if you want to look.
Basically, don't create your own instances of Lavacharts
use the one, singleton instance provided by the service provider.
Replace your $lava->
with \Lava::
I've answered this a few times around some of the closed issues if you want to look.
Basically, don't create your own instances of
Lavacharts
use the one, singleton instance provided by the service provider.Replace your
$lava->
with\Lava::
I already tried this but I always have an error of Class 'App\Http\Controllers\LA\Lava' not found
did you register the package's service provider? or did it autoload properly?
yes I already did install the package in composer and include the service provider already
the this that i don't understand form the installation is this line "Finally, require('vendor/autoload.php'); in your project and you are good to go!"
Are you using Laravel or just composer?
i'm using laravel framework, but i installed the lavacharts using composer update the proceed with the service provider and facade/alias that is usually need by installation
And you still don't have the alias? Can you use app("lavacharts")
or whatever they do now to get services from the container.