3

I have followed the tutorial https://github.com/kevinkhill/lavacharts to render the chart in my application based on Laravel 5.1. But Unable to render it. It gives me error LineChart('Stocks') was not found in View. Below is my controller code & view code. What changes are required to fix this issue?

ChartController.php

public function generatecharts()
{

$lava = new Lavacharts;
$stocksTable = $lava->DataTable();

 $stocksTable->addDateColumn('Day of Month')
            ->addNumberColumn('Projected')
            ->addNumberColumn('Official');




// Random Data For Example
for ($a = 1; $a < 30; $a++)
{
    $rowData = array(
      "2014-8-$a", rand(800,1000), rand(800,1000)
    );

    $stocksTable->addRow($rowData);
}

  $Chart = $lava->LineChart('Stocks')
                ->setOptions(array(
                    'datatable' => $stocksTable,
                    'title' => 'Stock Market Trends'
                  ));

return view('pages.analytics');

}

analytics.blade.php

@extends('layouts.app')
@section('title') analytics:: @parent @stop
@section('content')



<div class="row">
    <div class="page-header">
        <h2>Welcome to analytics</h2>
    </div>

</div>
<div id="stock-div"></div>
echo $lava->render('LineChart', 'Stocks', 'stock-div');
@linechart('Stocks', 'stocks-div');


@endsection

2 Answers 2

5

1) It stated in the documentation that if you are using Laravel, you need to change

$lava-> to \Lava:: (the slash is important)

2) Actually this line of code:

 echo $lava->render('LineChart', 'Stocks', 'stock-div');

is equivalent to this line:

 @linechart('Stocks', 'stocks-div');

So you have a repeating code here (just delete one line).

You have 3 options to put in your view:

You can use PHP tag:

<?php echo \Lava::render('LineChart', 'Stocks', 'stock-div'); ?>

or you can use this:

{!! \Lava::render('LineChart', 'Stocks', 'stock-div') !!}

or this simplified version

@linechart('Stocks', 'stocks-div');

Solution:

ChartController.php

public function generatecharts()
{

$stocksTable = \Lava::DataTable();

 $stocksTable->addDateColumn('Day of Month')
            ->addNumberColumn('Projected')
            ->addNumberColumn('Official');




// Random Data For Example

for ($a = 1; $a < 30; $a++)
{
    $rowData = array(
      "2014-8-$a", rand(800,1000), rand(800,1000)
    );

    $stocksTable->addRow($rowData);
}

  $Chart = \Lava::LineChart('Stocks')
                ->setOptions(array(
                    'datatable' => $stocksTable,
                    'title' => 'Stock Market Trends'
                  ));

return view('pages.analytics');

}

analytics.blade.php

@extends('layouts.app')
@section('title') analytics:: @parent @stop
@section('content')



<div class="row">
    <div class="page-header">
        <h2>Welcome to analytics</h2>
    </div>

</div>
<div id="stock-div"></div>

{!! \Lava::render('LineChart', 'Stocks', 'stock-div') !!}

@endsection
1
  • What to do in Laravel 4.2?
    – Vagabond
    Apr 27, 2017 at 12:52
1

HERE IS THE CODE FOR LAVACHARTS 3.0 AND LARAVEL 5.2

Controller

    $stocksTable = \Lava::DataTable();
    $stocksTable->addDateColumn('Day of Month')
        ->addNumberColumn('Projected')
        ->addNumberColumn('Official');

    // Random Data For Example
    for ($a = 1; $a < 30; $a++) {
        $stocksTable->addRow(["2014-8-$a", rand(800, 1000), rand(800, 1000)]);
    }

    //DON'T pass $Chart object to view, you get it via its label
    //options here: http://lavacharts.com/#datatables
    $Chart = \Lava::LineChart('this_is_the_label', $stocksTable, [
        'title'    => 'This works in laravel 5.2',
        'fontSize' => 24,
    ]);

View

<div id="stock-div"></div>
{!! \Lava::render('LineChart', 'this_is_the_label', 'stock-div') !!}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.