vanntastic / open_flash_chart forked from pullmonkey/open_flash_chart
- Source
- Commits
- Network (33)
- Downloads (2)
- Wiki (1)
- Graphs
-
Branch:
master
| name | age | message | |
|---|---|---|---|
| |
.gitignore | ||
| |
MIT-LICENSE | Thu Jul 24 08:48:52 -0700 2008 | |
| |
README.textile | ||
| |
Rakefile | Thu Jul 24 08:48:52 -0700 2008 | |
| |
assets/ | Thu Jan 08 12:50:06 -0800 2009 | |
| |
init.rb | Fri Dec 19 06:41:30 -0800 2008 | |
| |
install.rb | Fri Oct 24 20:44:29 -0700 2008 | |
| |
lib/ | ||
| |
tasks/ | ||
| |
test/ | Fri Nov 07 10:40:19 -0800 2008 | |
| |
uninstall.rb | Thu Jul 24 08:48:52 -0700 2008 |
OpenFlashChart
This is a fork of pullmonkey’s open flash chart plugin, it’s a great plugin that deserves a readme that is useful (to me). Here’s some links to helpful sources:
- Project page : http://www.pullmonkey.com/projects/open_flash_chart
- Original (non plugin) project page : http://teethgrinder.co.uk/open-flash-chart-2/
Installation
- run:
./script/plugin install git://github.com/vanntastic/open_flash_chart.git - the files should automatically copy, if they don’t you can run
rake ofc:install
Super Simple Example
The open_flash_chart plugin is best used when you have a action designated for generating a chart and another action for retrieving that chart request. Assuming you have a controller named test_it_controller.rb :
class TestItController < ApplicationController
# test_it/index
def index
respond_to do |wants|
wants.html {
@graph = open_flash_chart_object( 600, 300, url_for( :action => 'index', :format => :json ) )
}
wants.json {
chart = OpenFlashChart.new( "MY TITLE" ) do |c|
c << BarGlass.new( :values => (1..10).sort_by{rand} )
end
render :text => chart, :layout => false
}
end
end
end
# your layout file:
<html>
<head>
<%= javascript_include_tag 'swfobject' %>
</head>
<body>
<%= yield %>
</body>
</html>
# your view at: views/test_it/index.html.erb:
<%= @graph %>
Usage
OpenFlashChart
Generates a new flash chart object (best used in a json response), takes all the same arguments that you find at : http://teethgrinder.co.uk/open-flash-chart-2/. Here’s some quick examples to get you started with some charts:
# simple bar chart
@chart = OpenFlashChart.new "Weekly Performance" do |chart|
# equivalent to @chart = OpenFlashChart.new; @chart.add_element(Bar.new)
chart << Bar.new( :values => (1..10).sort_by{rand} )
# the default yellow bg is super ugly, let's keep it clean
c.set_bg_colour '#fff'
end
render :text => @chart, :layout => false
open_flash_chart_object(width, height, url, use_swfobject=true, base=“/”, swf_file_name=“open-flash-chart.swf”)
Instantiate a flash chart object, use in your controllers or views. It returns the html that will generate the chart.
Options:
- width : the width of your chart
- height : the height of your chart
- url : the url where the chart is being generated
- use_swobject : true/false (default:true) set whether or not you want to use swfobject, keeping the default is recommended
- base : the base path from which your chart will be requested, keeping the default is recommended
- swf_file_name : the name of the swf that generates the chart, you should never have to change this
Example :
# assuming /index?format=json is setup to return a chart instance
@graph = open_flash_chart_object( 600, 300, url_for(:action => 'index', :format => :json)
# now you can add this to your view
<%= @graph %>
open_flash_chart_object_and_div_name(width, height, url, use_swfobject=true, base=“/”, swf_file_name=“open-flash-chart.swf”)
Same thing as open_flash_chart_, but returns an array with the html and the divname, can be useful for working with the chart using js.
Example:
@graph = open_flash_chart_object_and_div_name(600, 300, url_for( :action => 'index', :format => :json)
# => [html, div_name]
# So if you want to use this chart in your views:
<%= @graph.first %>
open_flash_chart_object_from_hash(url, options={})
Same thing but allows you to pass in options as a hash.
Options:
- url : url where chart is being generated
- options={} : options hash:
- :div_name = name of div
- :base = the base path of where the chart is being generated
- :swf_file_name = the name of the swf that is being used to generate the chart, defaults to ‘/’, it’s highly recommended to keep the default
- :width = width of the chart
- :height = height of the chart
- :protocol = protocol of chart url request, defaults to ‘http://’, keeping the default is recommended
- :obj_id = the id for the html element, defaults to a randomly generated name
My Changes
- This readme
- Added rake task : ofc:install
Examples
Example above and more to follow here – http://www.pullmonkey.com/projects/open_flash_chart
Copyright © 2008 PullMonkey, released under the MIT license

