Open Flash Chart II - Multiple graphs on the same page
August 4th, 2008 by charlie
Got a comment asking about multiple graphs on the same page and if you need another controller or how that would all work. You only need one controller if you are going to have different graphs in the same view.
No graph for this example, just the code.
Open Flash Chart II examples.
Here is the code (the controller):
And in your view (index.html.erb):
Good Luck!
No graph for this example, just the code.
Open Flash Chart II examples.
Here is the code (the controller):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
class TestItController < ApplicationController def index @graph1 = open_flash_chart_object(600,300,"/test_it/graph_one") @graph2 = open_flash_chart_object(600,300,"/test_it/graph_two") @graph3 = open_flash_chart_object(600,300,"/test_it/graph_three") # and so on ... end def graph_one ... # put some OFC2 code here like in my examples end def graph_two ... # put some OFC2 code here end def graph_three ... # put some OFC2 code here end end |
And in your view (index.html.erb):
1 2 3 4 5 6 |
<script type="text/javascript" src="/javascripts/swfobject.js"></script> <%= @graph1 %><br/> <%= @graph2 %><br/> <%= @graph3 %><br/> |
Good Luck!
August 4th, 2008 at 03:39 PM Hi! Is BarStackValue missing? I'd need that class to set the colour of the rectangles in a stacked bar chart. Tried BarValue + set_colour but seems that BarStack does not accept BarValues.
August 4th, 2008 at 03:50 PM
@Xavier N. - yes it was missing ... sorry about that, see if that (the latest commits as of this comment) works for you.
August 4th, 2008 at 04:24 PM Man you rock, it couldn't be quicker. Working like a charm thank you!
August 4th, 2008 at 07:12 PM Is there a way to set the tooltip of each rectangle? BarStackValue#set_tooltip seems to have no effect.
August 4th, 2008 at 10:26 PM
@Xavier N. - Sorry but there does not seem to be a way to set tooltips by rectangle, neither BarStack nor BarStackValue seem to support tooltips in the swf ... I will keep looking though.
August 13th, 2008 at 03:37 PM This does NOT work for me. Only the last graph I put in the view is displayed, but in the page source, both appear.
In a new sample project:
rails test
script/generate controller test
-> (OFC2 install instructions)
index.rhtml:
test_controller.rb:
http://localhost:3000/test/ only displays the last bar graph. Why?
August 13th, 2008 at 03:40 PM Page source:
August 13th, 2008 at 03:59 PM Could this be the issue? There is two identical div names being generated for two separate flash objects...
and
August 13th, 2008 at 04:44 PM Yes, this is the issue. It is generating two identical id's for two separate objects. I mashed refresh a billion times until I got different IDs for each object.
Where can I fix this?
August 13th, 2008 at 06:10 PM
@Nick - wow good work. You must have a really fast server. That code is in RAILS_ROOT/vendor/plugins/open_flash_chart/lib/open_flash_chart_object.rb
I will come up with something. I am using time and apparently that is not good enough.
August 13th, 2008 at 07:48 PM Maybe generate a hash value for the chart based on time - and the contents of the chart / the chart object?
August 14th, 2008 at 08:10 AM
@Nick - Good call, just fixed it and it is out on github - http://github.com/pullmonkey/open_flash_chart/tree/master
I decided to use time and the url as the unique hash. Thank you for the suggestion.
August 14th, 2008 at 08:52 AM Charlie,
I did the same thing last night ;) Thanks for the fix.
Nick
August 27th, 2008 at 10:13 AM Sorry,it still does NOT work for me.
I met the same issue of Nick, even though I changed the Hash generator of div in file open_flash_chart_object.rb. What I did was add a "rand.to_s" to the base string for hash. And the "Open Flash Chart" plugin I used is the newest one I download 5 minutes ago. :(
Could Charlie think it over and fix it? Thanks a lot!
August 27th, 2008 at 11:07 AM
@Bear Young - could you post your HTML so I have something to work from? I am very interested in fixing it. Let me know.
August 27th, 2008 at 11:28 AM Sorry, I don't know your email address, Charlie. Could you send an email to me or tell me one way to contact with you, if it is unsuitable to publish your email at this page. Mine is bearyoung@gmail.com.