Google Charts In Email

82 views
Skip to first unread message

shriram krishnan

unread,
Oct 14, 2020, 2:35:10 AM10/14/20
to Google Visualization API
Hi All,

I need to send google charts to my emaill body, however my charts view is called via cron in codeigniter PHP and then the contents are rendered in backend and then passed directly for mailing.

I am unable to even capture image using getImageUri of google chart, as it is not rendered in UI/browser and passed directly to mail.

Can anybody suggest me how to do pass the same in mail.

Thanks & Regards
Sreeram Krishnan

Ian Webster

unread,
Oct 14, 2020, 8:43:33 PM10/14/20
to Google Visualization API
I had this problem and built a server-side renderer for Google Charts.  It is open-source and you can host it yourself.

If you are not able to run your own Node server, you can use the publicly hosted web endpoint, https://quickchart.io/google-charts/render.  This URL accepts a code parameter that runs your code in a Google Charts environment.

For example, take your drawChart function and add it to the URL:


It looks messy but it works.  Don't forget to URL encode your drawChart Javascript.

Parameters:
  • code: Javascript contents of drawChart (required)
  • packages: Comma-separated list of Google Visualization packages to load (defaults to "corechart")
  • width: Width of chart canvas in pixels
  • height: Height of chart canvas in pixels
  • mapsApiKey:  Maps key for geochart and maps
For more complex charts, I recommend POSTing your parameters as JSON.



Hope this helps,

Ian

shriram krishnan

unread,
Oct 15, 2020, 2:10:16 AM10/15/20
to google-visua...@googlegroups.com
Hi  Ian,

The nodejs server solution is great.

Regarding quick chart, I think it's paid one and for free version it has validity of time of 3 days of images in their server.

Thanks & Regards
Sreeram Krishnan
--
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/topic/google-visualization-api/J4LIqJtEXqs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualizati...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/3e017649-849a-44e9-bbf7-7627ef6b69afn%40googlegroups.com.

Ian Webster

unread,
Oct 15, 2020, 2:13:58 AM10/15/20
to Google Visualization API
The QuickChart server is open source so you can choose to self-host if you prefer.  The 3 day limit only applies to Chart.js images that are created with a short URL (because this requires server storage).  Fortunately, Google Charts images aren't created with a short URL, so the images don't expire - they are rendered on-demand according to the payload in the URL and not stored.

Ian

Reply all
Reply to author
Forward
0 new messages