在FPDF中使用Google Charts API生成的图形 [英] Using Google Charts API Generated Graphic in FPDF

查看:105
本文介绍了在FPDF中使用Google Charts API生成的图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那么,问题真的在标题中。由于图形是使用Javascript创建的,并且PDF是在服务器端生成的,所以我想知道是否有任何方法(如果有必要,可能是一种骇人的,不太漂亮的方式)将这些图形包含到使用生成的pdf中FPDF。



我想包括的图表示例: https://jsfiddle.net/srm8gzqg/3/
chart.draw(data,options);



编辑:
我几乎绝望了,因为我还没有找到一种可以在小提琴中创建图形的php替代方案。要求如下:


  • 上下行

  • 输入数据可以有浮点值

  • 轴左侧和底部正确的标签方向等。



我真的发现 no 用php编写的好的库,可以输出具有给定要求的图像文件(jpg,png等)。任何提示高度赞赏

解决方案

这是 jsfiddle 作为图像呈现的谷歌图表示例。您可以轻松地将可打印版本放入您的PDF中。



Google图表具有getImageURI方法,可为您提供您创建的图表的png。

  //在调用getImageURI()方法之前,等待图表完成绘制。 
google.visualization.events.addListener(chart,'ready',function(){
chart_div.innerHTML ='< img src ='+ chart.getImageURI()+'>' ;
});


Well, the question is really in the title. Since the Graphics are created with Javascript, and the PDF is generated on the server side, I was wondering if there was any way (may be a hackish, not-so-beautiful way if necessary) to include these graphics into a pdf generated using FPDF.

Example of a chart I'd like to include: https://jsfiddle.net/srm8gzqg/3/ chart.draw(data, options);

Edit: Im almost despairing, since I haven't found one php alternative in which I can create a graph like in the fiddle. Requirements are the following:

  • Lines from top to bottom
  • Input data can have float values
  • Axis on the left and bottom with correct label orientation etc.

I really found no good library written in php that can output an image file (jpg, png, etc) with the given requirements. Any hint is highly appreciated

解决方案

Here is a jsfiddle example of a google chart rendered as an image. You can easily put the "printable version" in your pdf.

Google charts have the getImageURI method that provides you with a png of the chart you created.

  // Wait for the chart to finish drawing before calling the getImageURI() method.
  google.visualization.events.addListener(chart, 'ready', function () {
    chart_div.innerHTML = '<img src="' + chart.getImageURI() + '">';
  });

这篇关于在FPDF中使用Google Charts API生成的图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆