Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stucked with adding multiple charts in to single dashboard #277

Open
KasunDilz opened this issue Oct 29, 2018 · 7 comments
Open

Stucked with adding multiple charts in to single dashboard #277

KasunDilz opened this issue Oct 29, 2018 · 7 comments

Comments

@KasunDilz
Copy link

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>
@kevinkhill
Copy link
Owner

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::

@oxiarius
Copy link

oxiarius commented Mar 8, 2021

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

@kevinkhill
Copy link
Owner

did you register the package's service provider? or did it autoload properly?

@oxiarius
Copy link

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!"

@kevinkhill
Copy link
Owner

Are you using Laravel or just composer?

@oxiarius
Copy link

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

@kevinkhill
Copy link
Owner

And you still don't have the alias? Can you use app("lavacharts") or whatever they do now to get services from the container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants