OFC2 4 Rails

mix advanced legends 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/mix_advanced_legends')

#in controller which is generating data for charts (for me it's charts_ofc2)
  
  def mix_advanced_legends
    title = OFC2::Title.new( :text => action_name.humanize , :style => "{font-size: 14px; color: #b50F0F; text-align: center;}")

    default_dot = OFC2::Dot.new( :colour => '#FF0000', :dot_size => 10, :halo_size =>12 )
    line_dot = OFC2::Line.new
    line_dot.dot_style = default_dot
    line_dot.set_tip('#val#<br>Your text here for line')
    line_dot.text= 'actual sales'
    line_dot.font_size= 12
    line_dot.colour= '#FF0000'
    line_dot.dot_size= 5

    bar = OFC2::Bar.new
    bar.set_tip('#val#<br>Your text here for bar')
    bar.text= 'forecast sales'
    line_dot.font_size= '12'
    bar.colour= '#00FF00'

    line_values= []
    bar_values= []
    x_labels_text = []
    y_labels_text = []
    max = 12

    0.upto(max) do |i|
      actual_sales = rand(max)
      forecast_sales = rand(max)
      line_values << OFC2::SolidDot.new(:value => actual_sales, :colour => '#FF0000', :tip => "actual sales: #{actual_sales}")
      bar_values << OFC2::BarValue.new(:top => forecast_sales, :colour => '#00FF00', :tip => "forecast sales:#{forecast_sales}")
      x_labels_text << "label #{i}"
      y_labels_text << "y label #{i}"
    end

    line_dot.values= line_values
    bar.values= bar_values


    x_labels = OFC2::XAxisLabels.new
    # x_labels.steps= 1
    x_labels.rotate= 'diagonal'
    # x_labels.colour = '#FF2ACB'
    # x_labels.size = 12

    x_labels_text[7] = OFC2::XAxisLabel.new(:text => '7', :colour => '#0000FF', :size => 20, :rotate => 90)
    x_labels_text[8] = OFC2::XAxisLabel.new(:text => 'eight', :colour => '#8C773E', :size => 16, :rotate => 70)
    x_labels_text[9] = OFC2::XAxisLabel.new(:text => 'nine',  :colour => '#2683CF', :size => 14, :visible => false)

    x_labels.labels= x_labels_text

    x = OFC2::XAxis.new
    x.colour= '#D7E4A3'
    x.grid_colour= '#A7E4A3'
    x.offset= true
    x.stroke = 10
    x.tick_height = 20
    # Add the X Axis Labels to the X Axis
    x.labels= x_labels

    x_legend = OFC2::XLegend.new( :text => "labels from 0 to #{max}" )
    x_legend.style= '{font-size: 20px; color: #FF8877}'



    y_labels = OFC2::YAxisLabels.new
    y_labels.colour = '#FF00FF'
    y_labels.size = 10
    y_labels.labels= y_labels_text

    y_legend = OFC2::YLegend.new( :text =>"Y description" )
    y_legend.style= '{font-size: 20px; color: #778877}'

    y_legend_right = OFC2::YLegend.new( :text =>"Y right description" )
    y_legend_right.style= '{font-size: 20px; color: #887788}'

    y_axis = OFC2::YAxis.new(:min => 0, :max => max, :steps => max/2)
    y_axis.stroke= 3
    y_axis.colour= '#AAAA00'
    y_axis.grid_colour= '#00FFF0'
    y_axis.tick_length= 20
    #    y_axis.steps= 2
    y_axis.labels= y_labels

    chart = OFC2::Graph.new
    chart.title= title

    chart.x_axis= x
    chart.x_legend=x_legend
    chart.y_legend=y_legend
    chart.y2_legend=y_legend_right
    chart.y_axis= y_axis
    chart.y_axis_right= y_axis
    chart.bg_colour= '#FFFFFF'

    chart << line_dot
    chart << bar

    render :text => chart.render
  end
  

# display graph in view (haml)
  =@graph