使用laravel-dompdf从chartjs导出图表

时间:2019-02-20 12:36:36

标签: dompdf laravel-5.7

我想问一下在以PDF格式绘制chartjs时是否能够使用laravel-dompdf。我在控制器中尝试了代码

TotalsController

public function create(Request $request)
{

           $recy = Recyclable::whereBetween('recycled_on', [$request->search1,$request->search2])->get();

           $comp = Composing::whereBetween('composted_on', [$request->search1,$request->search2])->get();

           $resi = Disposal::whereBetween('disposed_on', [$request->search1,$request->search2])->get();

           $disposecollect = Disposecollect::where(DB::raw("(DATE_FORMAT(created_at, '%Y'))"),date('Y'))->get();
           $totals = Charts::database($disposecollect,'bar','highcharts')
                ->title('ESWM Data')
                ->elementLabel("Total Weight in KGS")
                ->labels(['Recyclables','Compostables','Residuals'])
                ->dimensions(1000, 500)
                ->values([ $recy->sum('weight'), $comp->sum('weight'), $resi->sum('weight')])
                ->colors(["blue", "green", "gray"])
                ->responsive(false);

          // Send data to the view using loadView function of PDF facade
          $pdf = PDF::loadView('totalspdf', compact('totals'));
          // If you want to store the generated pdf to the server then you can use the store function
          $pdf->save(storage_path().'_filename.pdf');
          // Finally, you can download the file using download function
          return $pdf->download('overallreport.pdf');

 }

totalspdf.blade.php

<!DOCTYPE html>
<html>
<head>
  <h1 align="center">ECOTENEO</h1>
</head>
<body>
        <h3 align="center">Overall Collection Graph</h3>
        <br>

        {!! $totals->render() !!}

</body>
</html>

它可以工作,但问题是图表未显示在pdf中。

0 个答案:

没有答案