Posts met de tag « API»:

Dec 8 2007

A hands-on with the Google chart API

Inspired by my own previous post (how’s that for some blog-inbreeding?): a hands-on with the Google chart API.

Instead of going for a graph displaying how many visitors ended up here google-searching for the tits and ass of Veronique de Cock after my post on “toplessness”, I tried to create a graph comparing the chances of Yves Leterme becoming PM of Belgium, in correlation with the intelligence and sensibility of his statements about the Walloons.

Google API generated image

The red line represents his chances of becoming the next PM.
In 2006 and until the elections, it went uphill all the time (e.g. when he dropped the glasses, held CD&V and N-VA together when Jean-Marie DeDecker briefly joined the N-VA, waited long to go for the federal elections instead of staying Flemish minister-president …). At the elections, it was at its peak: he became the most popular politician, and won the elections with 800,000 preferential votes.
After which he went on a collision course with the French-speaking part of the country, showed a remarkable lack of leadership, and made almost no progress in forming a government. So his chances kept diminishing, resulting in a standstill-government, a formation of 176 days, a crisis of the regime. Everything bt a government Yves Leterme I.

The green line represents his finest statements about the Walloons.
They varied from questioning their ability to learn Dutch early on (which was intended ironically), to confusing the Belgian anthem with the Marseillaise (which was a cockup), through telling a French newspaper that keeping Belgium together is not a goal (which was unfortunate for somebody trying to become the leader of that same country), through refusing to speak with the RTBF, through comparing the RTBF with Radio Milles Collines (As he did today. This was the radio-station that called for a Hutu-Tutsi genocide in Rwanda!).
Where will he be headed from here (If he takes Godwin’s law any further, next up are: comparing Elio to Goebbels, telling Milquet she’s the bastard daughter of Lon Degrelle and finally calling for an military annexation of Brussels?).

How to build this graph

To make this chart, all it takes is a 384 character long call to the google-server. It retuns the image you see above.
Here is the call, broken down by its parts:

http://chart.apis.google.com/chart?

The basic statement. The API you’re calling is basically an image generator, with lots of options for displaying data. It is generated on the fly, and then displayed in your page. This means you could also fill it with dynamic data.

&chs=500×300

One of the required elements. Unfortunately, if you make it too small to fit the content in, the graph will be clipped. So that could be a tough call if you want to use it with dynamic data!

&chtt=Chances%20of%20Yves%20Leterme%20becoming%20PM|
vs.%20the%20wisdom%20of%20his%statements

The title. Unfortunately, there are no options for font. For a linebreak, ad a “|”. Encode spaces with “%20″.

&cht=lc

lc = line chart. The other options are Bar chart, Pie chart, Venn diagram and Scatter plot.

&chxt=x,y,r

the number of axes. The third axis is called “r”, not “z” as we’d name it over here

&chxr=0,0,100|1,0,100|2,100,0

These are the scales for the three axes. Positive from 0 to 100 for x and y. Negative (from 100 to 0) for the third one.

&chxs=1,ff0000,10|2,00ff00,10

The color and font size for axis 1 (red) and axis 2 (green). Axis 0 (the horizontal) stays unchanged.

&chxl=0:|2006|verk|Jun|Jul|Aug|Sept|Okt|Nov|Dec|Jan|Feb|

The axis labels for the 0-axis (the horizontal one)

&chco=ff0000,00ff00

The colors of the lines he’ll draw

&chls=3,6,3|3,3,0

More options for the lines: thickness, length of line segment, length of blank segment (to form a continuous or a dashed line)

&chd=s:a9zaaaaTPGAAA,GTdddddz188

The actual data.

&chf=c,lg,45,ffffff,0,000000,1|bg,s,EFEFEF

The background color (efefef grey for the entire graph – a gradient from white to black for the chart area).

The conclusion

The Google API for charts will have it’s use, but after toying around with it, I find it everything but an elegant solution:

  • Steep learning curve
  • No XML-data. If you want that, you’ll have to process it server-side first, or rely on javascript-importing, decoding, encoding and then sending it through the google chart api url
  • Limited set of chart-choices (this might grow)
  • 50.000 requests per page limit. Guess that means you can have a lot of graphs displayed, but they could’ve solved that with a caching mechanism, no?
  • Complicated url-forming. The url for the chart on top is 384 characters, and left a lot of the options untouched and is with a miniscule data-set. Somebody might build a tool where you can pick all kinds of options, import data and build you a url to the api from that. Until that day: it’s complicated and prone to errors
  • And finally: it’s has no features for accessibility. Since it returns only an image, the only way to make it slightly accessible is to put an alt or londesc with it. But you have no way of knowing how the graph will look before you display it (with dynamic data)… Heck, a flash version would even score better.

Some fun with google-charts:
Goatse man
The finger
Percentage of chart which looks like Pac-Man


Oct 19 2007

Slideoo: a cool tool for displaying your Flickr-photos

New to this blog: a flash-based banner on top displaying photo’s from my flickr-photostream. It’s on the homepage and on the archive page for this post (so if you don’t see it right now head over there

Was tempted into making this after reading on Mashable about a Belgian startup called Positiveluck, who just launched this service called Slideoo (or is it Slide∞ ?).

Writing a tutorial for this webservice would be quite simple:

  1. Go to slideoo.com

  2. enter a Flickr username (Preferably your own, if you don’t want to go into lengthy arguments with Flickr-users about whether or not an API can steal data)
  3. choose between a photoset or the photostream (newest photos on top) of that user
  4. Customize if you want small, thumbnail, medium or large images, and set options for width and the number of pictures to fetch)
  5. Hit “Create your Slideoo”.

Slideoo then quickly compiles the images into a horizontally scrolling flash-movie. It also provides you with the embed code to integrate your slideshow into the platform of your choice (Typepad, Myspace, Facebook, Blogger … most popular social networks and major blog platforms are represented through the magic of the cool widget-distribution network Gigya.

Cool, ain’t it? It ain’t eyepopping as other flickr-mashups as e.g. Tiltviewer, but I bet that will make you grow tired of it less quickly.

There is still room for improvement in the service, certainly:
The top functionality wanted would be to have a “random” function, so that on each reload the displayed photos would be different.
Another one is to distribute the flash-file, as integrating the thing on your blog now risks slowing down your site in two ways: the flickr-api has got to respond (but that’s taken care of by internet-giant Yahoo), nd slideoo has got to be able to handle the traffic.
And third: I’m sure some smart kid could write this in javascript + ajax instead of Flash, which could render it more accessible.