James Leo Mayol wrote:

*It has been suggested that I take screenshots and send the .png or .jpg to
> my target recipient - not a process that can be automated.*


Well, it *can* be automated, but it's not pretty. Not pretty at all.

Well, you don't actually need to take screenshots. The chart.getImageURI()
method will give you a (very long!) base64 encoding of the whole chart.

But the problem is, then what can you do with it? Javascript in the browser
can't write a .png file, and Google Charts is not compatible with Node.js.

I needed to do this for over 1200 graphs, every year or so. Right-clicking
and saving each of them obviously was not a reasonable option.

What I ended up doing was adding an undocumented URL parameter on my web
page, which tells my javascript code to stuff the generated graph into "web
storage" (a/k/a "DOM storage") in base64 encoded form. Google Chrome or
Chromium stores Web Storage in a Sqlite3 database file. Python has a module
which can read those.

You can see where this is going, can't you? So ugly it'd make a freight
train take a dirt road.

So I have a Python program which shells Chromium Portable (instead of
Chrome, to avoid interfering with whatever Chrome session is running),
passing in the URL that runs my graph-generating web page, with URL
parameters that tell it what graph to render, and which also includes the
magic export-command parameter. The web page's javascript generates the
graph using Google visualization tools, gets a base64 encoding via
getImageURI(0, and stuffs it into Web Storage, and then the javascript code
calls window.close() to close the page and the Chromium Portable browser.
The Python program then reads the Sqlite file left by Chromium, which
contains the base64 encoded graph. The Python program extracts the graph,
converts it from Base64 encoding, and writes it to a .png file on the
workstation.

Believe it or not, that works.

If you can stomach the stench, then send me an email, and I'll send you
some sample code.

Another, similar approach would be to have your javascript POST the
generated Base64-encoded graph to a PHP web page, which then writes it to a
.png file on the server.

I think that's but not quite as ugly. It would probably be a better
approach if you want the exported .png files to end up on the server,
instead of the workstation. Unfortunately, I don't have sample code for
that.

Dave
www.sealevel.info
(go to "Data" => "Spreadsheets & thumbnails," and then click any of the
"thumbnails" links)


On Tue, Mar 21, 2017 at 12:19 AM, James Leo Mayol <[email protected]>
wrote:

> I'm also looking for this kind of creating Google Charts without rendering
> in the browser. Did you by any chance have solution?
>
>
> I want to do something like this: Generate Google Charts images using
> CRON and add to PDF
> <http://stackoverflow.com/questions/42901874/generate-google-charts-images-using-cron-and-add-to-pdf>
>
>
> On Wednesday, March 9, 2016 at 12:50:46 PM UTC+8, JPC wrote:
>>
>> *I am trying to take server side acquired data, wrapped in HTML, PHP
>> code, Javascript or whatever, to build code then sent via mail so the the
>> recipient's browser shows him a graphic, *
>>
>> I've tried to use Google Charts Quickstart code (
>> https://developers.google.com/chart/interactive/docs/quick_start)
>>
>> I've tried for three days to get it to work in a PHP email executed from
>> the BASH shell, e.g. *php t5.php*
>> I am able to successfully send basic HML in the mail php template code
>> below.
>>
>> I took the quick-start code (above) and put it in the PHP email template
>> (below) , being careful to change the proper double quotes (") to single
>> quotes ('). See attached code (t5.php).
>>
>> *<?php*
>>
>> * $to .= '[email protected]';*
>>
>>
>> * $subject = 'Google Chart';*
>>
>> *$message = "*
>> *<html>*
>> *.*
>> *.see attached file with Google quick-start source*
>> *.*
>> *</html>*
>> *";*
>>
>>
>> *$headers = 'MIME-Version: 1.0' . "\r\n";*
>> *$headers .= 'Content-type:text/html;charset=UTF-8' . "\r\n";*
>>
>> *mail($to,$subject,$message,$headers);*
>> *?>*
>>
>> So, I'm wondering if I have an improper Header or if Javascript is an
>> issue or if I've done something stupid with quotes.
>>
>> I've searched Google, several forums, Github, etc. for to find a simple
>> working example of a Google Chart embedded in an email using a process that
>> can be automated. No joy.
>> Perhaps this cannot be done via mail and can only be done from a website?
>>
>> It has been suggested that I take screenshots and send the .png or .jpg
>> to my target recipient - not a process that can be automated.
>>
>>
>>    1. *If for some reason this can't be done, I'd like to know.*
>>    2. *If it can be done, I'd love to see an example. *
>>    3. *If there is a better way to send data, wrapped in HTML, PHP code,
>>    Javascript or whatever, to build code then sent via mail so the the
>>    recipient's browser shows him a graphic, I would love to know what it is. 
>> *
>>
>> Thank you.
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Google Visualization API" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/to
> pic/google-visualization-api/iNSCeQ2ljnI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to google-visualization-api@googl
> egroups.com.
> Visit this group at https://groups.google.com/grou
> p/google-visualization-api.
> To view this discussion on the web visit https://groups.google.com/d/ms
> gid/google-visualization-api/14c3963e-76f1-4cf4-8c52-d4f5b5
> 04b99f%40googlegroups.com
> <https://groups.google.com/d/msgid/google-visualization-api/14c3963e-76f1-4cf4-8c52-d4f5b504b99f%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-visualization-api/CALF61u4UUD5%2BrW2sEtRdOgUov8R5PFWM%3Dn267XVNhC%2BuWCpcnA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to