Home > Uncategorized > Generate static graph images for embedding into emails

Generate static graph images for embedding into emails

fsThe Google Graph API is great, but it’s Javascript based, so therefore unsuitable for embedding into emails, since most, if not all email clients will block the execution of Javascript.

The Google static chart API is an option, but it is officially deprecated, and may not be supported beyond 2015.

Here is an unusual solution, which can be used to generate an image from a web page, and then the resultant image can be embedded into a HTML based email.

First, I took Google’s simple “Pie chart” example, and replaced all the values with variables read from the query string: i.e.

function drawChart() {

var data = new google.visualization.DataTable();
data.addColumn(‘string’, getParameterByName(“datatitle”));
data.addColumn(‘number’, getParameterByName(“valuetitle”));
data.addRows(
eval(getParameterByName(“data”))
);

var options = {‘title’:getParameterByName(“title”),’width’:”100%”,’height’:”100%”};

var chart = new google.visualization.PieChart(document.getElementById(‘chart_div’));
chart.draw(data, options);
}

Put this online as a web-page, which can be called like this:

http://webtropy.site44.com/graph.html?title=Mobile+OS&datatitle=OS&valuetitle=Market+Share&data=%5B%5B%27iOS%27,15.6%5D,%5B%27Android%27,78.4%5D,%5B%27BlackBerry%27,1.9%5D,%5B%27Windows%27,3.2%5D%5D

Then using a thumbnail generator service, I can create an image from this:

http://immediatenet.com/t/fs?Size=1024×768&url=http://webtropy.site44.com/graph.html?title=Mobile+OS&datatitle=OS&valuetitle=Market+Share&data=%5B%5B%27iOS%27,15.6%5D,%5B%27Android%27,78.4%5D,%5B%27BlackBerry%27,1.9%5D,%5B%27Windows%27,3.2%5D%5D

– Which could then be embedded into an email using a simple <img> tag.

 

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: