?
Solved

Google charts to pdf

Posted on 2010-01-04
8
Medium Priority
?
4,307 Views
Last Modified: 2013-12-20
Is it possible to generate the PDF with PIE/BARchart data if we use google charts ?
0
Comment
Question by:Desire2change
  • 4
  • 3
8 Comments
 
LVL 11

Expert Comment

by:VanHackman
ID: 26172676

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
 

Author Comment

by:Desire2change
ID: 26172714
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
 
LVL 11

Expert Comment

by:VanHackman
ID: 26172827

Yes, that is a little bit problem that you could have, the solution is use the charts that are image based.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Desire2change
ID: 26172980
so you mean there is no way to store google charts as image on the system ??
0
 
LVL 11

Accepted Solution

by:
VanHackman earned 2000 total points
ID: 26173239

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
 

Author Comment

by:Desire2change
ID: 26178070
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
 
LVL 11

Expert Comment

by:VanHackman
ID: 26181753

@_@

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
 

Expert Comment

by:wayneas
ID: 33531233
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Sometimes we receive PDF files that are in the wrong orientation. They may be sideways or even upside down. This most commonly happens with scanned or faxed documents. It is possible to rotate the view of these PDFs with the free Adobe Reader produc…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month15 days, 18 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question