I just wanted to report back to the list on one chart-making technique
that has been working out well for me so far. I am using a popular open
source scientific and mathematical plotting package called Gnuplot.
http://www.gnuplot.info/
To use Gnuplot I started with a Ruby wrapper called rgplot (found on
RubyForge).
http://rubyforge.org/projects/rgplot
After playing with rgplot a while, I came to the conclusion that the
interface wasn’t really suited for my needs, so I studied the code,
learned a few key things, and ultimately came away with the one or two
lines of code that setup the pipe between Ruby and Gnuplot. Then I
wrote my own proof-of-concept wrapper to plot a couple of charts:
clustered bar charts, stacked bar charts, line graphs, etc.
Unfortunately, my wrapper is not really good enough for public
consumption, but I can explain how it works and you might be able to use
the same idea for your own applications. Basically, Gnuplot is run as a
subprocess from Ruby. You pass whatever commands and data you want to
Gnuplot through a stream to that subprocess. When it’s done plotting,
Gnuplot writes an image file to disk (JPG or other format). Finally you
create a Wx::Image from the image file and draw it as Wx::Bitmap on a
dc.
You can get pretty nice looking charts out of Gnuplot but you might have
to work at it. The Gnuplot syntax can be a pain, but it does come with
a lot of example files that help a lot. It also has an interactive GUI
that is handy for testing command syntax. One thing that Gnuplot cannot
do is pie charts. However, if you really need pie charts, they would be
easy enough to implement yourself by drawing directly with wx.
To implement your own wrapper for Gnuplot, I definitely recommend
studying rgplot (or use it “as is”, if it works for you). One thing to
look out for is that Gnuplot will be running asynchronously from
whatever else you are doing in Ruby or wx. So I use the on_timer event
to watch for the image file to be completed. After a lot of
experimentation, I found that (File.exists?(path) and File.size(path) >
0) is the best test to see if the image file is actually ready to be
loaded into wx. Also, if you need to create multiple charts at the same
time, you will need to write a manager that sequentially feeds jobs to
Gnuplot and then collects the resulting images. I was able to do that
without too much trouble, again using the on_timer event.
Maybe someday I’ll be able to put together a wrapper that I would be
willing to share. At the moment I’m not working on this actively, but I
hope to get back to it in a few months.
Best of luck,
P