ChartDirector is a proprietary library for charting available to most popular environments like Java or Ruby and so on. I had to use it at work to do some custom charting in Ruby. The application had requirement to work both under C Ruby and JRuby. ChartDirector provides Ruby library distributed as native binary, for Linux its ”.so”-file. Unfortunately this won’t work under Java and JRuby, but as library’s API is almost identical for each supported platform I created small wrapper Ruby class which integrates Java-based ChartDirector:
JRUBY=defined?(JRUBY_VERSION)
include Java
require 'ChartDirector.jar'
require 'servlet-api.jar'
include_class 'ChartDirector.Chart'

class ChartDirector < Chart
  include_class 'ChartDirector.Chart'
  include_class 'ChartDirector.BaseChart'
  include_class 'ChartDirector.XYChart'
  include_class 'ChartDirector.PieChart'
end
If you want more chart types just include more classess inside ChartDirector class declaration.

Now it can Ruby charting code needs some modifications

data0 = data.collect{|i| i["avg_response"]}
data1 = data.collect{|i| i["avg_max_response"]}
labels = data.collect{|i| i["c_name"]}

if JRUBY
  data0 = data0.to_java(:double)
  data1 = data1.to_java(:double)
  labels = labels.to_java(:string)
end

c = ChartDirector::XYChart.new(620, 280)
c.setPlotArea(300, 30, 300, 200, 0xf8f8f8, 0xffffff)
c.addLegend(50, 0, false, "arial.ttf", 8).setBackground(
    ChartDirector::Transparent)
c.xAxis().setLabels(labels)
c.xAxis().setLabelStyle("arial.ttf", 8, 0x000000, 0).setMaxWidth(300) 
c.xAxis().setTickLength(0)
c.swapXY(true)
c.yAxis().setTitle("Time in seconds")

layer = c.addBarLayer2(ChartDirector::Side)   
layer.addDataSet(data1, 0xff8080, "Average Max Response Time")
layer.addDataSet(data0, 0x80ff80, "Average Response Time")
layer.setOverlapRatio(0.5)

result_image = c.makeChart2(ChartDirector::PNG)
result_image = String::from_java_bytes(result_image) if JRUBY
send_data(result_image, :type => "image/png",:disposition => "inline")