Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Save Google Charts to the Server

Background: We're using Google Charts to create graphs of some data generated by our web app. The user creates a report and then emails that report. Trouble is, once the user opens the report in Microsoft Word, that program exhibits some odd behavior regarding the dynamically generated images.

So, using PHP, we want to save our dynamically generated charts on the server, because Word can handle simple linked images without any problems.

I'm kind of at a loss on how to proceed. Ideas?

like image 732
Gus Avatar asked Sep 17 '10 20:09

Gus


People also ask

Can Google Charts be used offline?

NO! Your users' computers must have access to https://www.gstatic.com/charts/loader.js in order to use the interactive features of Google Charts.

Is Google Charts cloud based?

Google Charts is a cloud-based business intelligence solution designed to help teams visualize data on their websites in the form of pictographs, pie charts, histograms and more.


2 Answers

<?
$imageData = file_get_contents('http://chart.apis.google.com/chart... etc');

// Attach image data as attachment to an email
//OR: 

file_put_contents('/path/to/save/image.png',$imageData);
?>
like image 60
Oliver O'Neill Avatar answered Sep 23 '22 19:09

Oliver O'Neill


The simplest way is probably to use something like curl to retrieve the image from Google and write it out to a file on your server. You could also just use fopen and related functions, if you turn on the allow_url_fopen option.

like image 32
Amber Avatar answered Sep 21 '22 19:09

Amber