laravel chart doesn't get the data from the controller

一个人想着一个人 提交于 2019-12-13 03:49:04

问题


i'm trying to get data to chart from the database. this how i wanted the data from database get row count according to the month in the date in Laravel

so i add that query. this is how controller looks like

class DashboardController extends Controller
    {
    public function admin()
    {

        $suppliers = SupplierData::all();
        $repcounter= SalesRep::count();
        $totalsales= SalesData::count();
        $totalrevenue=SalesData::sum('total_price');



        $chartdata = SalesData::selectRaw('COUNT(*) as count, YEAR(dateOfSale) year, MONTH(dateofSale) month')
            ->groupBy('year', 'month')
            ->get();

        $chart=Charts::database($chartdata,'bar','highcharts')
            ->title("Sales Details")
            ->elementLabel("Total Sales")
            ->dimensions(1000,500)
            ->responsive(false);

        return view('dashboard', compact('suppliers','repcounter','totalsales','totalrevenue','chart'));
    }

and here is my html code part

<div>
    {!!    $chart->html() !!}
        </div>

but this gives me empty chart. i don't know where i got it wrong. this is how it shows.

edited here is the console error,

Uncaught TypeError: Cannot read property 'querySelectorAll' of null
    at Object.c.createSvg (chartist.min.js:8)
    at e.d [as createChart] (chartist.min.js:8)
    at e.h (chartist.min.js:8)

来源:https://stackoverflow.com/questions/53465623/laravel-chart-doesnt-get-the-data-from-the-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!