Doubt in the use of the lavacharts library in Laravel consulted Mysql

Asked

Viewed 149 times

0

Gentlemen, I am using the Google library to Lavacharts, but I have the following result:

inserir a descrição da imagem aqui

On my controller I’m doing so:

$graf = new Lavacharts;
$valor = $graf->DataTable();
$valores = Produtos::select("nome as 0", "preco as 1")->get()->toArray();
$valor->addStringColumn("Preço")
        ->addNumberColumn("Nome")
        ->addRows($valores);
$graf->BarChart('Preço', $valor);

return view('home', ["graf" => $graf ]);

in my view I ask to display according to what the Library recommences

<div class="col-md-6" id="pop_div"></div>
<?= $graf->render("BarChart", "Preço", "pop_div"); ?>

Someone can give me a light?

Thank you

  • What appears in code (view-source)?

  • There’s nothing wrong, as if it’s running perfectly as you can see https://prnt.sc/mif76m @Eduardostuart

  • What appears to you if you dd($valores) (right after the $values=...) line? Make sure there are values to display?

  • yes, I have https://prnt.sc/mifb7e @Eduardostuart

  • Wouldn’t the columns be swapped? Just change the order of select, price first and then name.

  • Nothing returned, https://prnt.sc/mifgpx @Eduardostuart

  • my controller looks like this https://prnt.sc/mifk2j @Eduardostuart

Show 3 more comments

1 answer

0


Good afternoon @ Crsitiano, I do not know if you have already solved your problem, here I did so:

    $graf = new Lavacharts;
    $valor = \Lava::DataTable();
    $valores = Produtos::select("nome as 0", "preco as 1")->get()->toArray();
    $valor->addStringColumn("Preço")
            ->addNumberColumn("Nome")
            ->addRows(["NomeDaLinha", $valores]);

    \Lava::BarChart(
        'Preço', $valor, [
        'title' => 'Seu título aqui: '. $valores,
        'height' => 400
        ]
    );

    return view('home');

The view looked like this:

<div id="poll_div"></div>

<?= Lava::render('BarChart', 'valor', 'poll_div') ?>

And it worked, of course I adapted a code of my own for your... Try who knows it doesn’t work...

Abs...

  • Good morning @Gabrielsassaki already solved this post. Thank you so much for your help

Browser other questions tagged

You are not signed in. Login or sign up in order to post.