Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chart to wkhtmltopdf not working #328

Closed
andrewskm opened this issue Jul 2, 2020 · 4 comments
Closed

Chart to wkhtmltopdf not working #328

andrewskm opened this issue Jul 2, 2020 · 4 comments

Comments

@andrewskm
Copy link

What Version?

3.1.12

Issue

I am trying to display charts on a PDF using laravel-snappy (which uses wkhtmltopdf). This transforms the views easily into pdfs, so testing the html version, charts work fine.
I know the pdf needs time for the javascript to run, so I've applied the auto_run config to false so that I can run the window.lava.run() in a function when the body onloads.
A test to make sure the chart drawing feature is working is taking an example from Google Charts and placing in this function, which it does perfectly.

Below is some of my view code and wkhtmltopdf options.
Is there something I am missing?

View Code

    <script src="https://www.gstatic.com/charts/loader.js"></script>
    {!! Lava::lavajs() !!}
    <script type="text/javascript">
	function init()
	{
		var interval = setInterval(function()
                {
                       	try
                       {
                            window.google.charts.load('46', {packages: ['corechart']});
                            if(google.visualization !== undefined)
                            {
	                            window.status = 'ready';
	                            clearInterval(interval);
	                            window.lava.run();							                         
                            }
                        }catch(e)
                        {
                        	$('#display-error').html('Error parsing javascript: ' + e.message);
                                clearInterval(interval);
		        }
		}, 500);
	}
	</script> 
</head>
<body onload="init();">
   ...
    <div id="chart-contain"></div>
   ...
    {!! Lava::renderAll() !!}
</body>

wkhtmltopdf Options

'enable-javascript'      => true,
'javascript-delay'       => 3000,
'no-stop-slow-scripts'   => true,
'load-error-handling' => 'ignore', 
'enable-smart-shrinking' => true,
@andrewskm andrewskm changed the title Chart to wkthtmltopdf not working Chart to wkhtmltopdf not working Jul 2, 2020
@kevinkhill
Copy link
Owner

upon first glance... you don't need to include

<script src="https://www.gstatic.com/charts/loader.js"></script>

or

window.google.charts.load('46', {packages: ['corechart']});

as the library was designed to handle all that

@kevinkhill
Copy link
Owner

@kevinkhill
Copy link
Owner

Side question...

What do you think about this?

@andrewskm
Copy link
Author

I thought the library brought in the loader.js as well, but for some reason the charts do not load without it (this may be caused by the auto_run config being set to false).
The google package load is only set as a temp fix for this issue #326.

The LavaJs looks good, making it it's own library outside of lavacharts will allow it to be used on a broader spectrum where the framework may not be Laravel. Nice work!

kevinkhill added a commit that referenced this issue Aug 6, 2020
Pinning the charts version to `47` instead of `current` to resolve current issues with the latest version. #330 #329 #328
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants