Posts Tagged ‘FXRuby’

Easy Charts in FXRuby with the Google Chart API

InfoQ has just published an article written by Matthew Bass that introduces the Google Chart API and the gchartrb library, which you can use to programmatically generate URLs for use with Google Chart. It’s very easy to use this library to generate charts in your FXRuby applications. First, install the gchartrb gem:

$ sudo gem install gchartrb
You’ll need to poke around the gchartrb documentation to decide just what kinds of charts are supported; for this example, we’ll just use a bar chart example from Matthew’s article:

def bar_chart
  GoogleChart::BarChart.new('600x200', 'My Chart', :vertical) do |bc|
    bc.data 'Trend 1', [5,4,3,1,3,5], '0000ff'
    bc.data 'Trend 2', [1,2,3,4,5,6], 'ff0000'
    bc.data 'Trend 3', [6,5,4,4,5,6], '00ff00'
  end
end

The toescapedurl method for the BarChart object returns a URL from which we can retrieve the chart image data in PNG format. We can in turn use that data to construct an FXPNGImage, and place it inside an FXImageFrame:

FXImageFrame.new(self, nil, :opts => LAYOUT_FILL) do |f|
  f.image = FXPNGImage.new(app, open(bar_chart.to_escaped_url, "rb").read)
end

The result is a nice little bar chart, as shown here:

google_charts_demo.png

For reference, here’s the complete program:

Every Day I Write the Book

Some of the handful of readers of this blog already know about this, but I can now officially announce that I’m writing a book about FXRuby for the Pragmatic Bookshelf. I’m excited about this project because it will be the first book ever dedicated to the subject of FOX and FXRuby application development. I’m especially excited to be writing for the Pragmatic Programmers, who over the past few years have set a new standard of excellence for software development books.

The working title for the book is FXRuby: Create Lean and Mean GUIs with Ruby, and it will be published next April. The purpose of this book is to give you a head start on developing GUI applications with Ruby and FXRuby through a combination of tutorial exercises and focused technical information. It isn’t a comprehensive book on FXRuby programming, and it’s not a reference manual. What this book will do is get you over the initial conceptual hurdles and equip you with the practical information that you need to build your own applications.

The book is intended for software developers who are already comfortable with Ruby programming and who want to learn how to develop GUI applications with Ruby. No prior experience with GUI development is needed, but it’s intended to be useful both to newcomers as well as those who have worked with other GUI toolkits in the past. As the book gets closer to completion, we will be looking for help from technical reviewers. Watch this space for updates!