gpt4 book ai didi

javascript - wicked_pdf gem + Highcharts

转载 作者:行者123 更新时间:2023-11-28 15:11:47 24 4
gpt4 key购买 nike

我阅读了一些答案,但没有解决我的问题。

Html 图表效果很好,但当我使用 wicked_pdf 导出为 PDF 时,图表不显示。

我设置图表选项:

 plotOptions: {
series: {
enableMouseTracking: false,
shadow: false,
animation: false
}
},

并尝试给予 JavaScript 延迟。

根据我读到的一些帖子,我再次尝试在布局中包含和不包含 jquery 和/或 highcharts js 文件。

但没有什么对我有用,我的 wkhtmltopdf 库版本是:

wkhtmltopdf 0.12.2.1 (with patched qt)

我读到的所有答案都是 2 年前的,所以也许有人可以用更新的方法帮助我。

最佳答案

终于解决了。

有些步骤不是必需的,但无论如何我都会记下它以帮助大多数人:

1.- 更改 wkhtmltopdf 版本,我使用的是 0.12 ,现在我安装了

gem 'wkhtmltopdf-binary'

此 gem 可与 0.9 版本的 wkhtmltopdf 配合使用

2.- 从 Highcharts 中删除动画和其他内容。似乎没有它也可以工作,但最好确定的是,我正在本地测试,动画之类的东西会增加无法及时渲染完整图表的风险。

将此配置添加到图表容器文件中:

plotOptions: {
series: {
enableMouseTracking: false,
shadow: false,
animation: false
}
},

****注意:检查您是否已经在图表的另一部分设置了plotOptions,如果您已经将线条添加到现有的plotOptions中,如果您写入两次,它将不起作用。***

3.- 将 HTML 结构添加到布局 html 文件中,请记住 wicked_pdf 无法看到您的资源管道。

<HTML>
<HEAD> scripts </HEAD>
<BODY> charts and text </BODY>
</HTML>

4.- 在 PDF 布局 View (HEAD 标签)中包含内部和外部 JS 文件(如果有的话,包括 CSS 文件),在我的例子中,我使用 js 文件来存储图表模板并生成动态图表,如下所示:

   <script src="https://code.jquery.com/jquery-2.2.2.min.js" integrity="sha256-36cp2Co+/62rEAAYHLmRCPIych47CvdM+uTBJwSzWjI=" crossorigin="anonymous"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/heatmap.js"></script>
<%= wicked_pdf_javascript_include_tag "chart_templates/chart_bar_combined" %>

希望它有所帮助,这个答案结合了一些简短且解释较少的解决方案。

问候

关于javascript - wicked_pdf gem + Highcharts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36112020/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com