OFC2 4 Rails

scatter line 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/scatter_line')

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

    data_1 = []
    20.times do |i|
      data_1 << OFC2::ScatterValue.new(:x =>(i - 10), :y => (i - 10 - rand(5)))
    end

    data_2 = []
    20.times do |i|
      data_2 << OFC2::ScatterValue.new(:x =>(i - 10 - rand(5)), :y => (i - 10))
    end

    data_3 = []
    20.times do |i|
      data_3 << OFC2::ScatterValue.new(:x =>(i - 10 - rand(5)), :y => (i))
    end


    default_dot = OFC2::SolidDot.new( :colour => '#FF0000', :dot_size => 4, :halo_size =>4 )
    line = OFC2::ScatterLine.new(:colour => '#D600FF', :dot_style => default_dot, :values => data_1,
      :stepgraph => 'horizontal', :text => 'stepgraph horizontal')

    default_dot = OFC2::SolidDot.new( :colour => '#FFFF00', :dot_size => 4, :halo_size =>4 )
    line2 = OFC2::ScatterLine.new(:colour => '#D6AAFF', :dot_style => default_dot, :values => data_2,
      :stepgraph => 'vertical', :text => 'stepgraph vertical')

    default_dot = OFC2::SolidDot.new( :colour => '#F00F00', :dot_size => 4, :halo_size =>4 )
    line3 = OFC2::ScatterLine.new(:colour => '#D6AA00', :dot_style => default_dot, :values => data_3,
      :stepgraph => nil, :text => 'empty stepgraph')


    x = OFC2::XAxis.new(:min => -10, :max => 10)

    y = OFC2::YAxis.new(:min => -10, :max => 10)

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

    render :text => chart.render
  end
  

# display graph in view (haml)
  =@graph