Include chart (chart js) to PDF (snappy pdf) using laravel 5.3

0

Good, I want to include a chart (created by chart js) to a pdf file by Snappy pdf, but for some reason the view with which I create the pdf does not show the chart, this is what I have.

Controller

  public function chartPDF(){
    $chartjs = app()->chartjs
                    ->name('lineChartTest')
                    ->type('line')
                    ->size(['width' => 400, 'height' => 200])
                    ->labels(['January', 'February', 'March', 'April', 'May', 'June', 'July'])
                    ->datasets([
                       [
                         "label" => "My First dataset",
                         'backgroundColor' => "rgba(38, 185, 154, 0.31)",
                         'borderColor' => "rgba(38, 185, 154, 0.7)",
                         "pointBorderColor" => "rgba(38, 185, 154, 0.7)",
                         "pointBackgroundColor" => "rgba(38, 185, 154, 0.7)",
                         "pointHoverBackgroundColor" => "#fff",
                         "pointHoverBorderColor" => "rgba(220,220,220,1)",
                         'data' => [65, 59, 80, 81, 56, 55, 40],
                       ],
                       [
                         "label" => "My Second dataset",
                         'backgroundColor' => "rgba(38, 185, 154, 0.31)",
                         'borderColor' => "rgba(38, 185, 154, 0.7)",
                         "pointBorderColor" => "rgba(38, 185, 154, 0.7)",
                         "pointBackgroundColor" => "rgba(38, 185, 154, 0.7)",
                         "pointHoverBackgroundColor" => "#fff",
                         "pointHoverBorderColor" => "rgba(220,220,220,1)",
                         'data' => [12, 33, 44, 44, 55, 23, 40],
                       ]
                     ])
                     ->options([]);

  $pdf = \PDF::loadView('report.chart', compact('chartjs'))
  return $pdf->stream();
}

View

<!DOCTYPE html>
<html lang="en">
   <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>My Charts</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.min.js" type="text/javascript"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.bundle.min.js" type="text/javascript"></script>
  </head>
<body>
  <center>
      <div style="width:75%;">
        {!! $chartjs->render() !!}
      </div>
    </center>
</body>

Apparently when rendering the pdf view to the browser, the scripts tags do not create them and that's why it does not show the char. I would appreciate your help

    
asked by Deivid Fuentes 07.11.2017 в 22:41
source

0 answers