Laravel trying to display chart on welcome page

Viewed 135

I am trying to display a line graph on my welcome page of my website. I am using Laravel and Chartjs. I am able to display charts on other pages, but not on the main welcome page (the first page that is loaded when the website opened).

I have included :

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.min.js" charset="utf-8"></script> in the app.blade.php file,

-have created a chart class using php artisan make:chart LineChart Chartjs

-have used use App\Charts\LineChart; in my web.php file (I didn't create a welcome page controller)

-created the chart


$chart = new LineChart; $chart->labels(['A','B','C']);

$chart->dataset('Example1','line', [1,2,3]);

    return view('welcome',['chart' => $chart]);

Then accessed the chart in welcome.blade.php


{!! $chart->container() !!}
{!! $chart->script() !!}

How would I create a chart in my welcome page? Would I need to create a controller, or am I missing something? Thanks for any help

1 Answers

I have charts in some of my projects and always got problem drawing them until I used composer require consoletvs/charts:6.*.

Take a look to this page!

Anyway, use controllers.

Hope it helps. Regards.

Related