How to create a Open flash chart in Rails Application

Open flash chart is a free service, by using it you can create different types of charts easily.

To create a open flash chart in Rails application at first you need
the open flash chart plugin. To get this plugin go to your project folder and run:
ruby script/plugin install

After this Move the open_flash_chart.swf file into your RAILS_ROOT/public directory

Now create a controller and add the following code

def index
@graph_data = open_flash_chart_object(450,220,

def show_flash_chart
chart = draw_chart
render :text => chart
rescue Exception => error
logger.debug "error>>" + error.inspect

def draw_chart

chart_data = get_chart_data

#get data to display in chart
x_lebels = chart_data[:x_level]

# get x labels in a array
data = chart_data[:value]

# get y axis value
line_data_hashes = [{:color => "#e11456",
:legend => "Cost", :values => data}]
g =

#draw line
if line_data_hashes
line_data_hashes.each do |line|
g.line(2, line[:color], line[:legend], 10)

g.set_tool_tip('Year: #x_label#
Cost: #val#')
g.set_title("Sample Flash Chart",
'{font-size: 14px; color: #784016}')

#set minimum y axis value

#set maximum y axis value

#set number of steps in y axis

# set y axis legend
g.set_y_legend("Cost", 12, "#b9d800")

# set x axix value

#set x axis label's style
g.set_x_label_style(10, '#000000', 2)

#set x axis legend
g.set_x_legend("Year", 12, "#b9d800")

return g.render


In index.rhtml put the following code

<%= @graph_data %>

Now run it and you will see the magic


Anonymous July 4, 2008 at 3:43 AM  

Hi Ratul,
thx for the nice post. I encourage your enthusiasm. But I have some opinion to share with you. Using flash is not good for Data Driven objects for a web application. You may know, flash violates web3.0 compatibility. You can show a flash object on a smart client but unfortunately users at PDA or MIDP can't see flash objects on their mini browser :-(

And flash can be the big issue for security vulnerabilities through it's action script. Specially SaaS applications should never implements flashes.

FYI: The following article can be helpful for you.

Unknown July 10, 2008 at 3:10 AM  

Thanks rabbi for suggestion . I am looking for another chart api that help me to implement this type of simple chart


Total Pageviews


Twitter Updates
    follow me on Twitter