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

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

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

<script type="text/javascript">

const labels = [
  'January',
  'February',
  'March',
  'April',
  'May',
  'June',
];
const data = {
  labels: labels,
  datasets: [{
    label: 'My First dataset',
    backgroundColor: 'rgb(255, 99, 132)',
    borderColor: 'rgb(255, 99, 132)',
    data: [0, 10, 5, 2, 20, 30, 45],
  }]
};

const config = {
  type: 'bar',
  data,
  options: {
     animation: false,
        scales: {
            x: {
                grid: {
                tickColor: 'red'
                },
                ticks: {
                color: 'blue',
                }
            }
        }
  }
};

var myChart = new Chart(
    document.getElementById('myChart').getContext('2d'),
    config
);

</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生成工具相结合,一切似乎都可以正常工作,那么可能是最快的解决方案吗?

相关问题