Note: Version 2 of Open Flash Chart is available. Examples for version 2 are here.

Back to other graph examples

The Graph:



The Code:

This code in the controller:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def brandons_example
  g = Graph.new
  g.title("SPOON SALES", '{font-size: 26px;}')

  g.set_x_labels(%w(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec))
  g.set_bg_color('#FFFFFF')
  g.set_x_label_style(10,'#9933CC',1,1)
  g.set_x_axis_steps(1)
  g.set_y_max(60)
  g.set_y_label_steps(6)
  g.set_y_legend("Y-axis Legend", 12, "#736AFF")
  g.set_x_legend("X-axis Legend", 12, "#736AFF")

  #Need to set width and height since we aren't calling the open_flash_chart_object
  g.set_width(600)
  g.set_height(300)
  g.set_js_path('/projects/javascripts/')
  g.set_output_type('js')
  g.set_swf_path('/projects/')

  line = LineHollow.new(2,3,'#CC3399')
  line.key("Line Key", 10)
  line.data = [0,0,33,16,9,11,30,48,47,49,16,49]
  g.data_sets << line

  @graph = g.render
end
And this code in the view:
1
<%= @graph %>

Back to other graph examples