Chartjs-(Laravel) How to pull data from API Controller so that it will display in vue-chartjs

1👍

public function index()
{
    $mortality = Mortality::where('cycle_id', 1)->pluck('number_of_mortality');

    return response()->json($mortality);

}

In vue, https://vue-chartjs.org/guide/#chart-with-api-data do necessary things as in this link in your view & set the route to your index function here & do console.log(userlist) just below the call for debugging.

 try {
        const { userlist } = await fetch('route to your index()')
        console.log(userlist) 
        this.chartData = userlist
        this.loaded = true
      } catch (e) {
        console.error(e)
      }

Try this whole example https://appdividend.com/2018/02/23/laravel-vue-js-chartjs-tutorial-example/

0👍

You Can Try This:

public function index()
{
    $builder = new Mortality;
    $mortality = $builder->where('cycle_id',1)
                        ->pluck('number_of_mortality');
}

Leave a comment