简体   繁体   中英

Gem Chartkick charts not rendering on PDF

I'm using Rails 5.2.4, Gem Chartkick(3.3.1) and wicked_pdf(1.4.0). As many people wrote, I can also not display a pie chart on pdf through Chartkick and wicked_pdf, just "loading" is shown. The chart is correctly showing on html.

If someone could already solve this problem, please let me know which version of Chartkick and wicked_pdf was used?

I tried as below but no success:

  1. Add into box_report.pdf.erb
<%= wicked_pdf_javascript_include_tag "application", "chartkick" %>
  1. Add into controller
window_status: "FLAG_FOR_PDF"

plus add into application.js

setTimeout((function () {
    window.status = "FLAG_FOR_PDF";
    Object.keys(Chartkick.charts).forEach(function (key) {
        Chartkick.charts[key].redraw();
    });
}), 3000);
  1. Add wicked_pdf.rb
WickedPdf.config = {
  javascript_delay: 3000,
...
}
  1. Add into controller
javascript_delay: 3000,

For displaying Pie chart you need to use <%= pie_chart #count, width, height, id, and other options goes here %> . Make sure to use it in the template file you will be using.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM