Reputation: 107
When creating the pdf file using wicked pdf in rails no charts are being rendered. I have tried multiple versions of chart.js. Nothing works. Displaying the pdf as html works perfectly. Also, trying to set responsive: false in the chart.js but it did not work as well.
I'm using the following in head tag:
<%= wicked_pdf_javascript_include_tag "plugin_assets/rtcharts/javascripts/chart.min.js" %>
<%= wicked_pdf_javascript_include_tag "plugin_assets/rtcharts/javascripts/chart.helper.js" %>
<%= wicked_pdf_stylesheet_link_tag "plugin_assets/rtcharts/stylesheets/rtdashboard.css" %>
The following is the chart component:
<% charts = controlchart %>
<div class="rtdashboard grid-container grid-cols-2">
<% if charts.empty? %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% else %>
<% charts.each do |graph| %>
<div>
<%= render partial: 'rtcharts/bar',
formats: [:html],
:javascript_delay => 10000,
locals: graph %>
</div>
<% end %>
<% end %>
</div>
And this is in my controller:
format.pdf {
render template: 'qmcontrols/show',:type => 'application/pdf', pdf: "#{@project.identifier}_qmcontrol_#{@qmcontrol.id}",
margin: {left: 15, right: 15 },
:footer => {:center => "#{@project.name} / #{@location_details[0]['location_company']} / #{@qmcontrol.checkitem_location}", :right => '[page] / [topage]' },:javascript_delay => 5000,show_as_html: true
}
Upvotes: 2
Views: 1570
Reputation: 107
Finally i did that by converting the chart to an image first and then embedding it in my PDF. All thanks to @ty
You can see the following url for converting chart.js to image using quickchart.io Ref. Convert Chart.js data to image
Upvotes: 1