classTestItController < ApplicationControllerdefindex@graph = open_flash_chart_object(600,300,"/test_it/graph_code")enddefgraph_code# based on this example - http://teethgrinder.co.uk/open-flash-chart-2/horizontal-bar-chart.php title = Title.new("HBar Graph") hbar = HBar.new# could also do it one at a time with hbar.append_value(...) or# hbar.values << ... hbar.values = [HBarValue.new(0,4), HBarValue.new(4,8), HBarValue.new(8,11)] chart = OpenFlashChart.new chart.set_title(title) chart.add_element(hbar) x = XAxis.new x.set_offset(false) x.set_labels(['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']) chart.set_x_axis(x) y = YAxis.new y.set_offset(true) y.set_labels(["Make garden look sexy","Paint house","Move into house"]) chart.set_y_axis(y) render :text => chart.to_sendend
And here is the code (the controller): NOTE: You will need the latest plugin and open-flash-chart.swf (as of this article) for the tooltips to register properly.
classTestItController < ApplicationControllerdefindex@graph = open_flash_chart_object(600,300,"/test_it/graph_code")enddefgraph_code# we will have bars for each student subject combo bars = []# random colors to chose from colours = ["#459a89", "#9a89f9"]# the results results = Result.find(:all)# group by subject and use subject as the key results.group_by(&:subject).each do |subject, result|# 3d bar graph, could be any bar graph though bar = Bar3d.new bar.set_key(subject, 3) bar.colour = colours[bars.size] bar.values = result.map(&:test_score) bars << barend# some title title = Title.new("Test Results")# labels along the x axis, just hard code for now, but you would want to dynamically do this x_axis = XAxis.new x_axis.labels = ["Jack", "Jill"]# go to 100% since we are dealing with test results y_axis = YAxis.new y_axis.set_range(0, 100, 10)# setup the graph graph = OpenFlashChart.new graph.bg_colour = '#ffffcc' graph.title = title graph.x_axis = x_axis graph.y_axis = y_axis graph.elements = bars render :text => graph.to_sendend
Create a view, mine is index.html.erb for the test_it controller:
There were quite a few changes that were required to get it working with rails 2.1, so they are in the repository now.
So to install, you pretty much follow the same instructions from before.
The only thing I have not completely resolved is the use of the simple_cms_item partial that sits in the plugin's app/views/shared directory. I tried forever to use append_view_path to share the partial over. That worked, as in it found the partial, but the application layout went away, so instead, you can just copy the partial to your RAILS_ROOT/app/views/shared directory for now.
Additionally, you can install it through github: script/plugin install git://github.com/pullmonkey/simple_cms.git
And of course, a lot of you have asked how to just plain download it, well you can do that here, find the download button and click 🙂