【发布时间】:2020-05-27 05:59:07
【问题描述】:
我解释一下,我有一个 Laravel 项目,我需要在其中制作报告并在浏览器中显示以供下载。该报告需要有一些 Chartjs 制作的图表,这就是我所做的。
我的路线:
Route::get('/informe', 'informeController@procesar');
Route::get('/graph', 'informeController@graph');
Route::post('/save', 'informeController@graphStore');
Route::get('/up', 'informeController@graphUpdate');
一个非常大的控制器,但谁有这个伪代码。
public function graph()
{
return view('graphMaker');
}
public function graphUpdate(Request $request)
{
//get data from a database and send it to a view that requested data
return response()->json($data);
}
public function graphStore(Request $request){
//save the images obtained from the view using this commands in JS
//ctx2 = document.getElementById('donutchart');
//img = ctx2.toDataURL('image/png');
return route('/informe');
}
public function procesar(){
//get more data from the database and generate a pdf using mpdf
}
最后,该视图使用 Chartjs 和一个 JS 代码在 HTML 中制作 2 个图表,该代码使用所需信息更新图表。这是刀片视图。
所以我的问题是,是否有一种方法可以通过 laravel 使用视图和下载为 png 但在浏览器中不显示它来生成图表。
毕竟,如何在 Bowser 中显示 pdf?因为在进行查询时,它不会显示procesar() 输出($ mpdf-> Output ();)。
如果我忘记提及某事或需要信息,请询问我。谢谢大家。
【问题讨论】:
-
如果您已经将 pdf 保存到文件系统,您可以:
return response()->download($pathToFile)documentation。如果没有,请查看同一页面上的流式下载。 -
我试过了,没用。
$pathtofile必须是完整路径还是可以是相对路径?
标签: javascript php laravel view chart.js