OFC2 4 Rails

stacked 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/stacked_bar')

#in controller which is generating data for charts (for me it's charts_ofc2)
  
  def stacked_bar

    bar = OFC2::BarStack.new
    bar.values = []
    bar.values << [2.5, 5]
    bar.values << [7.5]
    bar.values << [5, OFC2::BarStackValue.new(:val => 4, :colour => '#ff0000')]
    bar.values << [2, 2, 2, 2, OFC2::BarStackValue.new(:val => 2, :colour => '#ff00ff', :tip => 'custop tip<br>#val# of #total#')]
    bar.colour= '#00FF00'
    bar.tip = 'X label [#x_label#], Value [#val#]<br>Total [#total#]'

    keys = []
    keys << OFC2::BarStackKey.new( :colour => '#ff0000', :text => 'red', :font_size => 13 )
    keys << OFC2::BarStackKey.new( :colour => '#ff00ff', :text => 'pink', :font_size => 13 )
    keys << OFC2::BarStackKey.new( :colour => '#00FF00', :text => 'green', :font_size => 13 )
    bar.set_keys keys

    x_labels = OFC2::XAxisLabels.new
    x_labels.steps= 1
    x_labels.labels = ['a', 'b', 'c', 'd']

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

    y = OFC2::YAxis.new

    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