Friday, March 11, 2011

Google Charts

Recently, I implemented a wrapper for the Google Chart API in Factor. The Visual REPL provides a really great way to do exploratory programming, such as my previous example of integrating Wolfram|Alpha with Factor.

Below are some various examples of using my google.charts vocabulary:

Pie Charts

At the end of 2008, Slava Pestov posted an article analyzing the usage of shuffle words in the core library. He created a usage-histogram word that counts the number of usages of a sequence of words:

: usage-histogram ( words -- assoc )
    [ [ name>> ] [ usage length ] bi ] { } map>assoc ;

We can then produce a pie chart showing the relative usage of various shuffle words:

Bar Charts

It might be fun to use a dictionary to count the number of words that start with each letter. We can use the dictionary available on most Unix-like systems to make a histogram and display the results as a bar chart:


Edward Tufte coined the term sparkline and described them as "data-intense, design-simple, word-sized graphics". They are often useful for quick visualizations of large data sets, for example a random sequence of numbers:

QR Codes

Recently, Fred Alger posted some source code which uses QR Codes and the MECARD format to share address book information with mobile users. We can convert arbitrary text into a QR Code for display:


We can use Tex to plot formulas:


We can make scatter plots, for example 100 random x,y points:

The code is available on my Github.


Anonymous said...

Very nice use of the charts API indeed!

tgkuo said...

Me too. When to see animated ones like AndEngine, Raphael, Processing, ....etc

kenanb said...
This comment has been removed by the author.
kenanb said...

Hi John, exciting post :) I somehow get the error below after the evaluation of "chart." word in every example. I am using the last Linux x64 build from

Generic word length does not define a method for the url class.
Dispatching on object: URL""

mrjbq7 said...

@kenanb: Thanks! Looks like I forgot to mention a small fix that I made to allow URL's to be used with http-image. It's not released yet.

If you'd like a workaround, you can do "chart>url present http-image." instead of "chart." (or modify chart. to look like that).