Open SnowDiamond opened 6 years ago
I'm having the same problem. It works when you use Chart.js version <= 2.6.0
I'm on chartjs 2.3.5 and it's not working for PDFs for us either. @SnowDiamond did you figure this out?
Yes, but I switched to chart.js 1.1.1.
Thanks. We ended up switching to puppeteer with a basic pdf generator script and it works fantastically and is about 4x faster to render.
I am experiencing the same problem as well.
The wicked_pdf_helpers do not seem to be loading the Chart.js library. Chart.js also doesn't load when I include it as a cdn.
Because of that I thought maybe there is a compatibility issue between Chart.js and wkhtmltopdf but even adding a polyfill from a comment in a related issue doesn't resolve the issue.
Has anyone figured this out? I am not able to load the chart in pdf.
All I get in the PDF is this:
I am using the following:
I had to downgrade to Chartkick 3
Is there a good tutorial on how to use this with Rails 6/7 and Chartkick 3/4?
Is there a good tutorial on how to use this with Rails 6/7 and Chartkick 3/4?
Check out the Chartkick website, it has separate instructions for Rails 5, 6 and 7.
Is there a good tutorial on how to use this with Rails 6/7 and Chartkick 3/4?
Check out the Chartkick website, it has separate instructions for Rails 5, 6 and 7.
I meant how to view Charts in PDF. My Chart.js 3 charts are not showing on PDF.
Many chart libraries have trouble with wkhtmltopdf
, since the webkit engine it is built on is equivalent to a very old version of Chrome (around Chrome 13, I think). That means it doesn't support a lot of ES6 style JavaScript, CSS3, Flexbox, or other modern-ish technologies used to build charting libraries.
It might be helpful to find and install a very old version of Chrome or Chromium and do your testing and debugging with that before trying to transform into a PDF. Maybe if you install some shims or polyfills it might work.
Also, many charting libraries need time to generate the charts and start with a loading screen of sorts, you may need to extend the javascript timeout options or window_status
when working with these.
Also, I suggest trying to include library code from a fully-qualified URL and using javascript_include_tag
over wicked_pdf_javascript_include_tag
(at least to debug, then maybe later converting to a file-based asset). The latter inlines the JS in a <style>
tag, and I've seen that get broken by large JS libraries that might include a </style>
in the source code.
In short, I don't have a lot of hope that most modern Chart libraries are going to be compatible with wkhtmltopdf
and thus wicked_pdf
, but if you find a combination that works, please let us know.
For me this combination of gems works surprisingly well, no shims javascript_delay
, window_status
etc needed anymore:
gem 'wicked_pdf', '~> 2.1.0'
gem 'chartkick', '3.4.2'
gem 'wkhtmltopdf-binary-edge', '~> 0.12.6.0
I've included a JS file containing the Chart.js and Chartkick JS code, as per the Chartkick documentation into my layout pdf.html.erb
like this:
<%= wicked_pdf_javascript_include_tag 'charts' %>
Some PDF report:
For me this combination of gems works surprisingly well, no shims
javascript_delay
,window_status
etc needed anymore:gem 'wicked_pdf', '~> 2.1.0' gem 'chartkick', '3.4.2' gem 'wkhtmltopdf-binary-edge', '~> 0.12.6.0
I've included a JS file containing the Chart.js and Chartkick JS code, as per the Chartkick documentation into my layout
pdf.html.erb
like this:<%= wicked_pdf_javascript_include_tag 'charts' %>
Some PDF report:
Hello @cseelus where do you add the JS file?
@JennsiS Into my pdf .erb
file.
Hi! Could you please help me with integrating Chart.js? I'm trying to render Chart.js in pdf, and it doesn't work for some reasons, just empty page. I tried setting
javascript_delay: 5000
and alsono_stop_slow_scripts: true
with no luck.Here is my code:
reports/show.pdf.slim:
reports_controller.rb:
P.S. With option
show_as_html: true
Chart.js works perfect.