OFC2 4 Rails

horizontal bar chart

# include js file on site
  = javascript_include_tag 'swfobject.js'

# in controller
  #ofc2(width, height, url, id =Time.now.usec, flash_attributes = {}, flash_params = {})
  @graph = ofc2(650,300, 'charts_ofc2/horizontal_bar')

#in controller which is generating data for charts (for me it's charts_ofc2)
  
  def horizontal_bar
    data = []
    0.upto(2) do |i|
      data << OFC2::HBarValue.new(y: i, :left => i, :right => 5 + i, value: i)
    end

    bar = OFC2::HBar.new
    bar.values= data
    bar.colour= '#00FF00'

    x_labels = OFC2::XAxisLabels.new
    x_labels.labels = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']

    x = OFC2::XAxis.new
    x.labels = x_labels

    y = OFC2::YAxis.new
    y.offset = 1
    y.max = 2

    y_labels = OFC2::YAxisLabels.new
    y_labels.size = 12
    y_labels.colour = '#0000FF'
    y_labels.labels= [
      "Make garden look sexy",
      OFC2::YAxisLabel.new(y: 1, :text => "Paint house", :colour => '#0000FF', :size => 20, :rotate => 90),
      "Move into house"]
    y.labels= y_labels

    chart = OFC2::Graph.new
    chart.title = OFC2::Title.new( :text => action_name.humanize , :style => "{font-size: 14px; color: #b50F0F; text-align: center;}")
    chart << bar
    chart.x_axis= x
    chart.y_axis= y
    render :text => chart.render
  end
  

# display graph in view (haml)
  =@graph