Problem rendering charts on PDF
aparedesBB opened this issue · 3 comments
What Version?
3.1.0
Issue
I'm using lavacharts to make some charts. If I render them in a laravel view (with blade) they display without any problem. I render them as images using ['png' => true]
in the charts options. But when I try to render them in a PDF (I started with DomPDF but now I use Laravel snappy) they doesn't show. I have a this theory where I suppose that if I render the charts putting the JS in the view this might work. But I tried with \Lava::getScriptManager()->bypassLavaJsOutput();
and it says that getScriptManager is not a method. Any suggestions please? NOTE: If i put anything else in the view it does shows in the PDF.
Controller Code (chart creation code)
for ($i = 0; $i < count($cancelaciones); $i++) {
$cancelaciones[$i] = array_values($cancelaciones[$i]);
}
$reasons = \Lava::DataTable();
$reasons->addStringColumn('Reasons')
->addNumberColumn('Percent')
->addRows($cancelaciones);
$pie = \Lava::PieChart('IMDB', $reasons, [
'title' => 'Motivos de cancelación',
'elementId' => 'chart-div-pie',
'legend' => ['position' => 'labeled'],
'height' => 500,
'png' => true
]);
$pdf = PDFSnappy::loadView('salut', array('promedio' => $promedio, 'observaciones' => $observaciones, 'calificacionPromedio' => $calificacionPromedio, 'sugerencias' => $sugerencias, 'pedidos' => $pedidos, 'cancelaciones' => $cancelaciones, 'quejas' => $quejas));
$pdf->setOption('enable-javascript', true);
$pdf->setOption('javascript-delay', 10000);
$pdf->setOption('enable-smart-shrinking', true);
$pdf->setOption('no-stop-slow-scripts', true);
return $pdf->download('Reporte.pdf');
View Code
{!! \Lava::render('PieChart', 'IMDB', 'chart-div-pie') !!}
@aparedesBB got any luck with this problem? i'm having timeout when trying to export to pdf too :(
@brnbp I had to change the library to make charts. In order to be able to render charts on server side so them can be shown without problems in the PDF I used this one.
http://luddep.se/notebook/2008/04/13/charts-php-and-google-charts-api/
It has less chart types but it works for what I need. Hope it helps!
unless you use some javascript engine to run the resulting code from the library, you can't export to PDF. Google Charts is a JS api, it needs to be ran through a browser engine of sorts. (I have successfully used PhantomJS to create PNGs serverside)