Thursday,Jul3,

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 http://svn.pullmonkey.com/plugins/trunk/open_flash_chart/

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,
'/flash_chart/show_flash_chart',false,'/',true)
end



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



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 = Graph.new

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

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
g.set_y_min(0)

#set maximum y axis value
g.set_y_max(100)

#set number of steps in y axis
g.set_y_label_steps(5)

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

# set x axix value
g.set_x_labels(x_lebels)

#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

end


In index.rhtml put the following code

<%= @graph_data %>


Now run it and you will see the magic


Total Pageviews

446,284

Tags

Abstract Entities ActiveMessaging Amazon SQS Asynchronous mail sending Context Menu Contiuous Integration Deploy Rails Application Deployment by Capistrano Design pattern Ext GWT Ext GWT DnD Framework Filter Grid GWT GXT Chart GXT Editable Grid GXT Example GXT Grid Grouping GXT Tree Filter GlassFish Google App Engine Grid GroupLayout JDO JPA JPQL JTable JavaMail API ListView Local Paging Mapped Superclass Open flash chart Reflection Remote pagination Session Management Strategy pattern XTemplate cruisecontrol.rb filter JTable Row flash chart gxt java reCAPTCHA
Twitter Updates
    follow me on Twitter

    Followers