我在应用程序中使用Highcharts来渲染图表。一切正常,除非我想将具有图表的页面转换为PDF。我在用着 wicked_pdf. 。这是我的控制器的节目方法:

 format.pdf do
          render :pdf => "report",
                 :template => "/quarters/report.pdf.erb",
  end

my /quarters /report.pdf.erb文件看起来像我的show.html.erb for HighCharts:

    <div id="testcollections" style="width: 600px;"></div>

<!-- jQuery for testing collections charts -->
<script type="text/javascript" charset="utf-8">
$(function () {
  new Highcharts.Chart({
    chart: { renderTo: 'testcollections' },
    title: { text: 'Test Collections' },
    plotOptions: {
            series: {
                dataLabels: {
                    enabled: true,
                    formatter: function() {
                        return this.y;
                    }
                }
            }
        },

    series: [{
    name: 'Collections',
    type: 'area',
    color: '#5b81b4',
    data: <%= Quarter.where('quarters.client_id=?',      @quarter.client_id).map(&:collections) %> 
    },
    {
    name:'Average Collections',
    type: 'area',
    color: '#999',
    data: <%= Quarter.includes(:client).group('clients.specialty',      'quarters.year', 'quarters.quarter')
    .average('quarters.collections').values.map(&:to_f).to_json %>
    }]
  });
});
</script>

在我的节目页面上,这是下载PDF文件的链接:

<%= link_to 'PDF', { :action => "show", :format => :pdf } %> |

问题是图表没有渲染,只是空白。我知道 这里 您应该调用“ Wicked_pdf_javascript_include_tag”,但它给了我“未定义方法`javascript_src_tag'”的错误。

有什么想法吗?

有帮助吗?

解决方案

看起来javascript_src_tag在Rails 3.1中消失了:http://apidock.com/rails/actionview/helpers/assettaghelper/javascript_src_tag

您可以用这样的东西将呼叫替换为Wicked_pdf_javascript_include_tag:

<script type="text/javascript" src="file://#{Rails.root.join('public','javascripts','highcharts.js')}"></script>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top