laravel-snappy: chart.js Chart does not show up in pdf
This has been mentioned a few times already (#145 / #73) and I’ve tried all the given possibilities, but just can’t get the chart in my view to print to the PDF snappy generates. I’m on Laravel 5.4 and would appreciate some help from anyone who’s got this working.
Here’s my code: In my controller, I pull in data from an API call and the chart is generated with the Fx3costa\LaravelChartJs package:
`$chartjs = app()->chartjs ->name(‘lineChartTest’) ->type(‘line’) ->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’ => $pageViews, ]
])
->options([]);`
I then try to generate the PDF like this:
` $data = array(‘chartjs’=> $chartjs, ‘user’=> $user, ‘pageViews’=> $pageViews);
return $pdf = PDF::loadHTML(view('admin.analytics.show', $data))
->setOption('enable-javascript', true)
->setOption('images', true)
->setOption('javascript-delay', 13000)
->setOption('enable-smart-shrinking', true)
->setOption('no-stop-slow-scripts', true)
->download('test.pdf');`
In my view, I call the Chartjs script via cdn in the header and render the chart in a div:
<div style = "width: 600px; height: 400px;"> {!! $chartjs->render() !!} </div>
Thanks in advance.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 19 (2 by maintainers)
You can see this working example right here https://github.com/admicaa/larabook or you can see this article https://medium.com/@almestaadmicadiab/laravel-snappy-for-pdf-with-charts-e5c9b757d6dd