A Ruby module to generate simple .png graphics using Google Chart API
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



A Ruby module to generate simple graphics using Google Chart API online plotting service.


roogle_graphics is a Ruby module that makes it very easy to generate simple PNG images containing text and polygons. It does this by compiling your graphic commands into a URI and sending it to the Google Chart API online service for rendering.

The main advantage of this approach is that it requires no external libraries or packages. It will work from any environment that can issue an HTML GET request.

One disadvantage is that we're asking the Google Chart API to do something it really wasn't designed to do, so you don't have total control over things like font style. But even so, roogle_graphics can generate useful and good looking graphics, like this:

sample graphic

simple example

To use roogle_graphics, the basic steps are:

  • Instantiate a Plot object
  • Create Text and Polygon elements, calling Plot#add_element() on each one to add it to the plot.
  • Call Plot#generate_uri (or Plot#generate_img_uri) and submit the resulting string to the Google Chart API service.
  • Display the resulting .png

For example:

require 'roogle_graphics'
include RoogleGraphics

def hello_world
  plot_width = 300
  plot_height = 300
  x0 = plot_width/2
  y0 = plot_height/2

  # set up a plot with a lemony gradient background
  plot = Plot.new(:width => plot_width, :height => plot_height, :fill_color2 => 'ffffcc')

  # add a pale blue box, centered at the middle of the plot
  box = [[-130,-130],[130,-130],[130,130],[-130,130],[-130,-130]]
  polygon = Polygon.new(x0, y0, box, :fill_color => 'ccccff')

  # add text with a simple raised-text effect
  msg = "hello, world!"
  text = Text.new(x0+2, y0-2, msg, :color => 'ffffff', :size => 40, :halign => :center, :valign => :middle)
  text = Text.new(x0, y0, msg, :size => 40, :halign => :center, :valign => :middle)

  # generate the URI that, when passed to Google, will produce the plot

This generates the somewhat fearsome URI of:


which, passed to Google's charting service will produce a png file that looks like this:

hello world graphic

See the examples file for additional samples.

Notes (and limitations)

We are severely subverting Googles Chart API when we use it to plot simple polygons and polygons -- it was originally designed to make good looking quantitative graphs (a job it does very well). So it is not surprising that there are several limitations:

Want to help?

You know the drill: fork the repository, work your magic, let me know when I should merge yours back in.

Share and enjoy!