Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending google visualization chart to email

Can we send Google Visualization chart to an email client? I tried to copy paste the javascript code while sending the email, but its been removed on the fly by gmail.

Thanks and Regards.

like image 434
iMatoria Avatar asked Feb 19 '12 07:02

iMatoria


People also ask

How do you insert a chart in Gmail?

Click the "Charts" tab and select the chart type that you want to use. With the proper chart selected, click the "Insert" button to insert the chart into the spreadsheet.

How do I print a Google chart?

Google Charts can be printed directly from your browser, or from JavaScript via the print() function. If you want to provide access to a PNG image of a chart, you can use the getImageURI() method.

Are Google charts accessible?

Google charts While the charts themselves are generated using HTML5 and SVG additional accessibility is provided by also including the chart data in an accessible HTML table for screen readers.


2 Answers

Disclaimer: I'm Image-Charts founder.

6 years later! Google Image-Charts is deprecated since 2012, and as an indiehacker, I don't want to rewrite from scratch an image generation backend each time I started a new SaaS to just be able to send charts in email...

That's why I've built Image-charts 👍 and added gif animation on top of it 🚀(chart animations in emails are awesome!!), no more server-side chart rendering pain, no scaling issues, it's blazing fast, 1 URL = 1 image chart.

https://image-charts.com/chart
?cht=bvg
&chd=t:10,15,25,30,40,80
&chs=700x300
&chxt=x,y
&chxl=0:|March '18|April '18|May '18|June '18|July '18|August '18|
&chdl=Visitors (in thousands)
&chf=b0,lg,90,05B142,1,0CE858,0.2
&chxs=1N**K
&chtt=Visitors report
&chma=0,0,10,10
&chl=||||+33% !|x2 !

enter image description here

enter image description here

enter image description here

enter image description here

like image 107
FGRibreau Avatar answered Oct 12 '22 11:10

FGRibreau


I ran into this problem as well. In order to send a chart in email, you need to render it as an image because email clients strip Javascript.

If you're using Google Charts, you'll have to run the Javascript and then export it using getImageURI. To automate this, you need a headless renderer like puppeteer.

The solution to the problem is open source. I wrapped chart rendering in a library and web server: https://github.com/typpo/quickchart. This web service handles the rendering details, all you do is call the API with your data.

For example, define your chart in the query parameters:

https://quickchart.io/chart?width=500&height=300&c={type:'bar',data:{labels:['January','February','March','April','May'],datasets:[{label:'Dogs',data:[50,60,70,180,190]},{label:'Cats',data:[100,200,300,400,500]}]}}

The above URL renders this image:

QuickChart image render

Hope this helps!

like image 25
ty. Avatar answered Oct 12 '22 10:10

ty.