图表js版本3未显示在引擎wkhtmltopdf的pdf中

trnvg8h3  于 2021-09-23  发布在  Java
关注(0)|答案(1)|浏览(316)

我正在尝试使用wkhtmltopdf生成pdf,其中有图表js。图表js版本3.4.x
我写了下面的html来生成图表
你好
js代码:

  1. <script type="text/javascript">
  2. const labels = [
  3. 'January',
  4. 'February',
  5. 'March',
  6. 'April',
  7. 'May',
  8. 'June',
  9. ];
  10. const data = {
  11. labels: labels,
  12. datasets: [{
  13. label: 'My First dataset',
  14. backgroundColor: 'rgb(255, 99, 132)',
  15. borderColor: 'rgb(255, 99, 132)',
  16. data: [0, 10, 5, 2, 20, 30, 45],
  17. }]
  18. };
  19. const config = {
  20. type: 'bar',
  21. data,
  22. options: {
  23. animation: false,
  24. scales: {
  25. x: {
  26. grid: {
  27. tickColor: 'red'
  28. },
  29. ticks: {
  30. color: 'blue',
  31. }
  32. }
  33. }
  34. }
  35. };
  36. var myChart = new Chart(
  37. document.getElementById('myChart').getContext('2d'),
  38. config
  39. );
  40. </script>

图表在html中运行良好

发出命令后
wkhtmltopdf—javascript延迟1000http://localhost/pdf_test/index.html testpdf101
我有段落,但没有图表。我在版本图表JS2.9.4中测试过同样的过程,它运行良好。为什么它在版本3中不起作用?如何为chart js 3.4.x版生成pdf?

fdbelqdn

fdbelqdn1#

另一个pdf工具(hiqpdf)也遇到了同样的问题,这些工具使用的引擎似乎与InternetExplorer11一样支持javascript/jquery版本。在ie11中查看页面时,您可能会看到与chart.js相关的语法错误,因为chart.js不再支持ie11,它们似乎使用了pdf呈现工具中无法使用的语法。。我花了整整一周的时间来解决这个问题,最后选择了使用2.9版本的chart.js,使用v3迁移guid向后…使用2.9,与pdf生成工具相结合,一切似乎都可以正常工作,那么可能是最快的解决方案吗?

相关问题