Fork me on GitHub

Project Notes

#250 Gems

Notes on ruby options for chart generation that support output as an image

Notes

These are my notes on ruby options for chart generation, specifically:

  • supporting common chart types (line, column, bar, pie, XY)
  • supporting multiple data series
  • with customizable chart decoration (titles, axis, tick marks etc)
  • and supporting output to image file or data stream (bitmap or vector) i.e. not for web rendering
  • supporting ruby 2.7.2 or above on MacOS and Linux
  • ideally no additional non-ruby dependencies

Trawling for options:

Legacy Google Image Charts API

The Google Image Charts API is used to dynamically generate charts with a URL string.

The API was deprecated in 2012 and was retired on March 18, 2019. It is still running and working. However note the warning from Google that it may disappear any day:

While the dynamic and interactive Google Charts are actively maintained, we officially deprecated the static Google Image Charts way back in 2012. This gives us the right to turn it off without notice, which may happen soon.

There were a number of Ruby gems created to take advantage of the service. They all still work as of Jan 2023.

Note: the new Google Charts service doesn’t meet my requirement for non-interactive generation. However to use Google Charts, there are gems for that e.g.:

  • google_visualr is a wrapper around the Google Chart Tools that allows anyone to create the same beautiful charts with just Ruby; you don’t have to write any JavaScript at all.
  • chartkick - Create beautiful JavaScript charts with one line of Ruby. Supports Google Charts, Highcharts and Chart.js

gchartrb

The gchartrb gem is the ancient and original wrapper for the Google Image Charts API, hosted on Google Code.

It has not been maintained since 2008, but it does still work. It generates HTTP requests, but the Google Image Charts API automatically redirects these to be handled over HTTPS.

A simple example.rb generates graphs like this:

line_chart

gchart

The gchart gem arrived at around the same time as gchartrb as one of the first community-supported wrappers for the Google Chart API.

After the RubyForge shutdown, the code was migrated to github

It has not been maintained since 2009, as community focus appears to have shifted to the googlecharts gem.

A simple example.rb generates graphs like this:

line_chart

googlecharts

The googlecharts gem also arrived at around the same time as gchartrb as one of the first community-supported wrappers for the Google Chart API.

After the RubyForge shutdown, the code was migrated to github, but it has ceased to be maintained since 2015 and is now archived.

A simple example.rb generates graphs like this:

line_chart

ruby-graphviz

The ruby-graphviz gem provides an interface to layout and generate images of directed graphs in a variety of formats (PostScript, PNG, etc.) using GraphViz.

It requires Graphviz to be installed.

For testing on Mac I used brew: brew install graphviz. .. I ran into issues with that (some source repos not having valid SSL certs etc) so I’ve abandoned this test for now…

gruff

The gruff gem Requires rmagick

A simple example.rb generates graphs like this:

line_chart

rubyvis

The rubyvis gem is a Ruby port of Protovis, a Javascript visualization toolkit. Pure ruby.

A simple example.rb generates graphs like this as SVG:

line_chart

Converted to PNG using rmagick:

line_chart.png

Credits and References

About LCK#250 rubygraphing
Project Source on GitHub Return to the Project Catalog

LittleCodingKata is my collection of programming exercises, research and code toys broadly spanning things that relate to programming and software development (languages, frameworks and tools).

These range from the trivial to the complex and serious. Many are inspired by existing work and I'll note credits and references where applicable. The focus is quite scattered, as I variously work on things new and important in the moment, or go back to revisit things from the past.

This is primarily a personal collection for my own edification and learning, but anyone who stumbles by is welcome to borrow, steal or reference the work here. And if you spot errors or issues I'd really appreciate some feedback - create an issue, send me an email or even send a pull-request.

LittleArduinoProjects LittleModelArt More on my blog