wickedpdf は JavaScript グラフをレンダリングしますか?
ルビー 1.8.7
レール - 2.3.8
私のコードは正常に動作し、ビューは正常に表示されます.flotはグラフを希望どおりにプロットします...しかし、pdfファイルを見るとすべて空白です。
他の誰かが同様の問題に遭遇しましたか?
コントローラ:
def graph
@now=Time.now
@graph = [0,0] / some sort of dataset /
pdf = render_to_string :pdf => "graphs", :orientation => 'Landscape', :font_size => 11
save_path = Rails.root.join('pdfs', @now.to_date.to_s+'_graphs.pdf')
File.open(save_path, 'wb') do |file|
file << pdf
end
意見:
<script language="javascript" type="text/javascript" src="/javascripts/jquery.js"></script>
<script language="javascript" type="text/javascript" src="/javascripts/jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="/javascripts/jquery.flot.navigate.js"></script>
<%= wicked_pdf_stylesheet_link_tag "pdf" -%>
<%= wicked_pdf_javascript_src_tag "jquery" %>
<%= wicked_pdf_javascript_src_tag "jquery.flot" %>
<%= wicked_pdf_javascript_src_tag "jquery.flot.navigate" %>
<script type="text/javascript">
$(function () {
var options = {
lines: { show: true },
points: { show: true },
xaxis: { mode: "time", timeformat: "%m/%y", minTickSize: [1, "day"], tickSize: [1, "month"]}
};
var graph = <%= @graph.to_json %>;
$.plot(placeholder,graph.data,options);
}
<div id="placeholder" style="width:1000;height:500px"></div>
ヘルパー:
module WickedPdfHelper
def wicked_pdf_stylesheet_link_tag(*sources)
css_dir = Rails.root.join('public','stylesheets')
sources.collect { |source|
"<style type='text/css'>#{File.read(css_dir.join(source+'.css'))}</style>"
}.join("\n").html_safe
end
def wicked_pdf_image_tag(img, options={})
image_tag "file:///#{Rails.root.join('public', 'images', img)}", options
end
def wicked_pdf_javascript_src_tag(jsfile, options={})
javascript_src_tag jsfile, options
end
def wicked_pdf_javascript_include_tag(*sources)
sources.collect{ |source| wicked_pdf_javascript_src_tag(source, {}) }.join("\n").html_safe
end
module Assets
def wicked_pdf_stylesheet_link_tag(*sources)
sources.collect { |source|
"<style type='text/css'>#{read_asset(source+".css")}</style>"
}.join("\n").html_safe
end
def wicked_pdf_image_tag(img, options={})
image_tag "file://#{asset_pathname(img).to_s}", options
end
def wicked_pdf_javascript_src_tag(jsfile, options={})
javascript_include_tag jsfile, options
end
def wicked_pdf_javascript_include_tag(*sources)
sources.collect { |source|
"<script type='text/javascript'>#{read_asset(source+".js")}</script>"
}.join("\n").html_safe
end
private
def asset_pathname(source)
if Rails.configuration.assets.compile == false
File.join(Rails.public_path, asset_path(source))
else
Rails.application.assets.find_asset(source).pathname
end
end
def read_asset(source)
if Rails.configuration.assets.compile == false
IO.read(asset_pathname(source))
else
Rails.application.assets.find_asset(source).to_s
end
end
end
end