Google charts to pdf

Is it possible to generate the PDF with PIE/BARchart data if we use google charts ?
Desire2changeAsked:
Who is Participating?
 
VanHackmanCommented:

No, You can store google charts as image and after that use it in your PDF.
Here the code Snippet, I just code it now and works fine for me. =)
<?php

// Google Chart to Image - By VanHackman

	$chart = file_get_contents('http://chart.apis.google.com/chart?cht=p3&chd=t:90,49&chs=350x150&chl=Foo|Bar');
	
	$handle = fopen("ChartImage.png", "w");
	fwrite($handle, $chart);
	fclose($handle);
	
	echo '<img src="ChartImage.png" alt="crash"/>';

?>

Open in new window

0
 
VanHackmanCommented:

No, you must use another library/class to handle the PDF generation.

I suggest you FPDF

http://www.fpdf.org/
http://www.fpdf.org/en/tutorial/index.php

So, you generate your Chart and after that, you manipulate and use FPDF to put it in a PDF.

=)

I hope that my answer helps you!
0
 
Desire2changeAuthor Commented:
I am using exactly the same that is FPDF
but the problem is I have google charts in my report
when i say $pdf->Image('google chart url')
it says invalid image format

So, I am using the following code to save the google chart as image .
but the resultant file graph.png is created with 0 bytes i.e. blank

$url="http://chart.apis.google.com/chart?chs=350x200&chd=t:20,10,30,10&cht=p3&chl=20|10|30|10&chdl=Total Number Of Machines Scanned|Low|High|Medium&chdlp=b&chco=00FF00|0000FF|FF0000|00FFFF";

file_put_contents('uploads/graph.png',file_get_contents($url));
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
VanHackmanCommented:

Yes, that is a little bit problem that you could have, the solution is use the charts that are image based.
0
 
Desire2changeAuthor Commented:
so you mean there is no way to store google charts as image on the system ??
0
 
Desire2changeAuthor Commented:
the same thing i did and not working for me, strange!
is there any setting i need to change
when i say:
$chart = file_get_contents('http://chart.apis.google.com/chart?cht=p3&chd=t:90,49&chs=350x150&chl=Foo|Bar');

the $chart is empty
0
 
VanHackmanCommented:

@_@

So rare, The code snippet works perfect for me.
Do you have the fopen_wrappers() enable?

"A URL can be used as a filename with this function if the fopen wrappers have been enabled."

Do you have to turn "ON" the "allow_url_fopen" in your php.ini

http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen
0
 
wayneasCommented:
I was having trouble with this code and found that by urlencoding the labels it worked for me - probably because my labels were being drawn from a database and had spaces in. Just extra information in case any one else has the same problem I had.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.