lavacharts icon indicating copy to clipboard operation
lavacharts copied to clipboard

Stucked with adding multiple charts in to single dashboard

Open KasunDilz opened this issue 6 years ago • 7 comments

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>

KasunDilz avatar Oct 29 '18 06:10 KasunDilz

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

kevinkhill avatar Jan 13 '19 18:01 kevinkhill

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

oxiarius avatar Mar 08 '21 08:03 oxiarius

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

kevinkhill avatar Mar 11 '21 22:03 kevinkhill

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

oxiarius avatar Mar 12 '21 04:03 oxiarius

Are you using Laravel or just composer?

kevinkhill avatar Mar 12 '21 04:03 kevinkhill

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

oxiarius avatar Mar 12 '21 05:03 oxiarius

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

kevinkhill avatar Mar 14 '21 02:03 kevinkhill