Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/52.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Wkhtmltopdf命令错误:with Chart.js responsive:false选项_Ruby On Rails_Ruby On Rails 5_Chart.js_Wkhtmltopdf - Fatal编程技术网

Ruby on rails Wkhtmltopdf命令错误:with Chart.js responsive:false选项

Ruby on rails Wkhtmltopdf命令错误:with Chart.js responsive:false选项,ruby-on-rails,ruby-on-rails-5,chart.js,wkhtmltopdf,Ruby On Rails,Ruby On Rails 5,Chart.js,Wkhtmltopdf,我正在用wicked_pdf和wkhtmltopdf(版本0.12.4)在rails中生成Charjs图。我已经将wkhtmltopdf gem从0.12.3.1版更新到了0.12.4版,因为它使用了大量RAM内存,并且在生成长PDF时花费了太多时间,但是charjs图形可以工作。现在,对于新版本,当响应图表选项设置为false时,会发生错误: 将其设置为true时,即使父块具有“宽度”和“高度”设置,也不会出现任何错误,但它不起作用 我不知道如何用最新版本的wkhtmltopdf解决这个问

我正在用wicked_pdf和wkhtmltopdf(版本0.12.4)在rails中生成Charjs图。我已经将wkhtmltopdf gem从0.12.3.1版更新到了0.12.4版,因为它使用了大量RAM内存,并且在生成长PDF时花费了太多时间,但是charjs图形可以工作。现在,对于新版本,当响应图表选项设置为false时,会发生错误:

将其设置为true时,即使父块具有“宽度”和“高度”设置,也不会出现任何错误,但它不起作用

我不知道如何用最新版本的wkhtmltopdf解决这个问题,gem降级是不可能的

请帮忙

我尝试过为父容器和chartjs画布设置宽度和高度,在WKHTMLTFD中设置更多javascript\u延迟,在charjs中没有动画,使用charjs doc推荐的函数进行onbeforeprint回调

html

pdf格式

pdf = WickedPdf.new.pdf_from_string(
    template,
    pdf: "Report_#{cost_report_type}", javascript_delay: 2000,
    header: { content: header, spacing: 10 },
    footer: { center: 'Pagina [page] de [topage]', spacing: 5 },
    margin: {
      top: 35,
      bottom: 15
    },
    encoding: 'UTF-8',
    zoom: 0.8,
    orientation: 'Portrait'
  )
var ctx = document.getElementById(canvas_id).getContext('2d');
    new Chart(ctx, {
      type: 'horizontalBar',
      data: {
        datasets: [{
          label: 'Real',
          data: data1,
          backgroundColor: backgroundColor1,
          borderColor: borderColor1,
          borderWidth: 1
        },
          {
            label: 'Proyectado',
            data: data2,
            backgroundColor: backgroundColor2,
            borderColor: borderColor2,
            borderWidth: 1
          }
        ],
        // These labels appear in the legend and in the tooltips when hovering different arcs
        labels: labels
      },
      options:{
        title: {
          display: true,
          text: title,
          fontSize: 10,
          fontColor: '#00397B',
          lineHeight: 3
        },
        responsive: false,
        legend:{
          position: 'bottom',
          fontSize: 10
        },
        scales: {
          xAxes: [{
            ticks: {
              // Include a dollar sign in the ticks
              callback: function(value, index, values) {
                return 'USD ' + number_to_cl(value);
              }
            }
          }]
        },
        tooltips: {
          callbacks: {
            label: function(tooltipItem, data) {
              var label = 
                data.datasets[tooltipItem.datasetIndex].label || '',
                value = 
    data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];

              if (label) {
                label += ': ';
              }
              label += 'USD ' + number_to_cl(value);
              return label;
            }
          }
        }
      }
    })
pdf = WickedPdf.new.pdf_from_string(
    template,
    pdf: "Report_#{cost_report_type}", javascript_delay: 2000,
    header: { content: header, spacing: 10 },
    footer: { center: 'Pagina [page] de [topage]', spacing: 5 },
    margin: {
      top: 35,
      bottom: 15
    },
    encoding: 'UTF-8',
    zoom: 0.8,
    orientation: 'Portrait'
  )