Home > database >  HighCharts in Laravel Errors
HighCharts in Laravel Errors

Time:05-23

Hello Everyone i have this trouble now with my laravel project i am trying to add pie chart from highcharts, i added the javascrips in home.blade.

But a got this issue and i need to resolve, look at this.

The Error :

json_decode(): Argument #1 ($json) must be of type string, array given

The Code:

Controller:

 $decisiones = Visita::all();

        $puntos = [];

        foreach($decisiones as $decision )
        {

            $puntos = ['name' => $decision['registrante'], 'y' => $decision['id']]; 
        }

 return view('Reportes.ReporteTomaDecision', ["data" => json_decode($puntos)]);

the View

data: <?= $data ?>

this my variable from controller

CodePudding user response:

It looks more like you have to return json in the view so you have to encode the data.

Then try this:

$decisiones = Visita::all();
$puntos = [];

foreach ($decisiones as $decision) {

    $puntos = ['name' => $decision['registrante'], 'y' => $decision['id']]; 
}

return view('Reportes.ReporteTomaDecision', ["data" => json_encode($puntos)]);

view:

<?= $data ?>

CodePudding user response:

 $decisiones = Visita::all();

        $puntos = [];

        foreach($decisiones as $decision )
        {

            $puntos[] = ['name' => $decision['registrante'], 'y' => $decision['id']]; 
        }

$data = json_encode($puntos);

 return view('Reportes.ReporteTomaDecision', compact($data)]);
 
 
 go to ReporteTomaDecision blade 
 
 {{$data}}

  • Related