首页 > 解决方案 > 在 Laravel 8 中将图表刀片视图转换为 pdf

问题描述

我想将波纹管刀片视图转换为 pdf 文档。

刀片视图包含 Canvasjs 图表。我导出刀片视图时的标题和段落正常显示。但只有图表没有显示。

 <!DOCTYPE HTML>
 <html>
 <head>
 <script>
 window.onload = function() {
  
 var chart = new CanvasJS.Chart("chartContainer", {
   animationEnabled: true,
   theme: "light2",
   title:{
     text: "Gold Reserves"
   },
   axisY: {
     title: "Gold Reserves (in tonnes)"
   },
   data: [{
     type: "column",
     yValueFormatString: "#,##0.## tonnes",
     dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?>
   }]
 });
 chart.render();
  
 }
 </script>
 </head>
 <body>
 <div id="chartContainer" style="height: 370px; width: 100%;"></div>
 <script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
 </body>
 </html>



public function build()
    {
        $pdf = FacadesPdf::loadView('Mails.myTestMail',["details"=>$this->details]);
        return $this->subject('Mail from UVARA ROI CALCULATOR.')
        ->attachData($pdf->output(),'report.pdf')
        ->view('Mails.myTestMail');
    }

我正在后端级别转换它,我知道我可以使用 javascript 来制作它,但我想动态生成视图并导出为 pdf 并通过电子邮件发送。

提前致谢。

标签: phplaravelchartslaravel-8canvasjs

解决方案


推荐阅读