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

"Class 'App\Http\Controllers\Lava' not found" - AJAX query #317

Open
Metalkaiser opened this issue Nov 20, 2019 · 2 comments
Open

"Class 'App\Http\Controllers\Lava' not found" - AJAX query #317

Metalkaiser opened this issue Nov 20, 2019 · 2 comments

Comments

@Metalkaiser
Copy link

What Version?

khill/lavacharts" : * 3.1.12

Issue

Trying to create a Pie chart through ajax query. Getting the following response:
"Class 'App\Http\Controllers\Lava' not found"

I tried changing the Lava:: lines to \Lava::, then a different error occurs:
jquery.min.js:2 GET http://127.0.0.1:8000/create?queryArr%5B%5D=anapaula.chiodaro&queryArr%5B%5D=carlos.arruda&startPeriod=2007-07-01&endPeriod=2007-09-31 net::ERR_CONNECTION_REFUSED

Also, the main idea is to create a for loop that can create the rows. Any suggestion?
Thanks in advance

Controller Code (chart creation code)

<?php

namespace App\Http\Controllers;

use App\caol;
use Illuminate\Http\Request;
use Khill\Lavacharts\Lavacharts;

class CaolController extends Controller
{
    public function pizza(Request $request)
    {
        if ($request->ajax()) {
            $pizza = \Lava::DataTable();
            $pizza->addStringColumn('Desempenho')
                ->addNumberColumn('ganancia') 
                ->addRow([$request["nameArr"][0], $request["pizzaArr"][0]])
                ->addRow([$request["nameArr"][1], $request["pizzaArr"][1]])

            \Lava::PieChart('Pizza',$pizza, [
                'title' => 'Pizza',
                'is3D' => 'false',
                'slices' => [
                    ['offset' => 0]
                ]
            ]);
            return response()->json(
                "Pizza declared"
            );
        }
    }

View Code

$("#results").html("");
							var pizzaArr = new Array();
							for (var x = 0; x < nameArr.length; x++) {
								var totalpizza = 0;
								for (var y = 0; y < totalconsult[x].length; y++) {
									totalpizza = totalpizza + totalconsult[x][y];
								}
								$("#results").append(
									nameArr[x] + " = " + totalpizza + "<br>"
								);
								pizzaArr[x] = totalpizza;
							}
							$.ajax({
								url: "/pizza",
								type: 'GET',
								dataType: 'json',
								data: {
									pizzaArr:pizzaArr,
									nameArr:nameArr,
								},
								success: function(pizzares) {
									console.log(pizzares);
								},
								error: function(res) {
									console.log(res);
								}
							});
@Metalkaiser
Copy link
Author

Metalkaiser commented Nov 20, 2019

UPDATE:

I changed the function in the controller as you can see here:

public function pizza(Request $request)
{
if ($request->ajax()) {
$lava = new Lavacharts;
$pizza = $lava->DataTable();
$pizza->addStringColumn('Desempenho')
->addNumberColumn('ganancia');
for ($x=0; $x < count($request["pizzaArr"]); $x++) {
$pizza->addRow([$request["nameArr"][$x], $request["pizzaArr"][$x]]);
}
$lava->PieChart('Pizza',$pizza, [
'title' => 'Pizza',
'is3D' => 'false',
]);
return response()->json(
$lava->render('PieChart','Pizza','results')
);
}
}

Now I'm getting success response, but I'm trying to figure out how to call the graph properly.
Right now, this code gives me a result where I can only see the graph title.

When I use $("#results").append(pizzares); on the success: function(pizzares) of $.ajax, this is what I got:

> <div style="position: relative;">
> 	<div dir="ltr" style="position: relative; width: 1408px; height: 200px;">
> 		<div aria-label="A chart." style="position: absolute; left: 0px; top: 0px; width: 100%; height: 100%;">
> 			<svg width="1408" height="200" aria-label="A chart." style="overflow: hidden;">
> 				<defs id="_ABSTRACT_RENDERER_ID_2"></defs>
> 				<rect x="0" y="0" width="1408" height="200" stroke="none" stroke-width="0" fill="#ffffff"></rect>
> 				<g>
> 					<text text-anchor="start" x="131" y="24.25" font-family="Arial" font-size="15" font-weight="bold" stroke="none" stroke-width="0" fill="#000000">Pizza</text>
> 					<rect x="131" y="11.5" width="1146" height="15" stroke="none" stroke-width="0" fill-opacity="0" fill="#ffffff"></rect>
> 				</g>
> 				<g></g>
> 			</svg>
> 			<div aria-label="A tabular representation of the data in the chart." style="position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden;">
> 				<table>
> 					<thead>
> 						<tr>
> 							<th>Desempenho</th>
> 							<th>ganancia</th>
> 						</tr>
> 					</thead>
> 					<tbody>
> 						<tr>
> 							<td>Ana Paula Fontes Martins Chiodaro</td>
> 							<td>25,582.14</td>
> 						</tr>
> 						<tr>
> 							<td>Carlos Flávio Girão de Arruda</td>
> 							<td>231,498.18</td>
> 						</tr>
> 					</tbody>
> 				</table>
> 			</div>
> 		</div>
> 	</div>
> 	<div aria-hidden="true" style="display: none; position: absolute; top: 210px; left: 1418px; white-space: nowrap; font-family: Arial; font-size: 15px; font-weight: bold;">Pizza</div>
> <div>

I suppose that the graph itself should be in the empty tag.

Any idea of how to properly call the graph on my view?

Thanks in advance

@Metalkaiser
Copy link
Author

UPDATE: I solved the issue. The problem was in the line $pizza->addRow([$request["nameArr"][$x], $request["pizzaArr"][$x]]);. The $request["pizzaArr"][$x] part was string.

I solved the issue by changing to (float)$request["pizzaArr"][$x]]

I leave the issue open in case there is any comment anyone want to make.

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

1 participant