23 Jul
Open Flash Chart II Plugin for Ruby on Rails (OFC2)
Ok, already, I heard ya
The open flash chart (version 2 - OFC2) plugin is done (really just started) and it is out on github.
Examples for version 2 are here.
I rewrote the open flash chart plugin (started from scratch) to work with json like teethgrinder does here.
This time I think it is much slicker and a lot easier to work with.
I haven't tried much more than bar graphs, all the functionality is there for other types of graphs, just not tested.
Graph that this example produces:
So it is out there, and if you are willing to try it out, here is how:
- rails testing_ofc_2
- cd testing_ofc_2
- script/plugin install git://github.com/pullmonkey/open_flash_chart.git
- script/generate controller test_it
- Add the following to the test_it_controller.rb in RAILS_ROOT/app/controllers:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
class TestItController < ApplicationController def index @graph = open_flash_chart_object(600,300,"/test_it/graph_code") end def graph_code title = Title.new("MY TITLE") bar = BarGlass.new bar.set_values([1,2,3,4,5,6,7,8,9]) chart = OpenFlashChart.new chart.set_title(title) chart.add_element(bar) render :text => chart.to_s end end
- Add the following to index.html.erb in RAILS_ROOT/app/views/test_it/:
1 2 3 4 5
<script type="text/javascript" src="/javascripts/swfobject.js"></script> <%= @graph %>
- Copy swfobject.js from the plugin's assets/ directory (will make this happen at install time later) to your RAILS_ROOT/public/javascripts directory
- Copy open-flash-chart.swf from the plugin's assets/ director to your RAILS_ROOT/public/ directory
- script/server
- Browse to http://localhost:3000/test_it
- Let me know how it goes, thanks.

I’ve download the plugin and it worked first time. Great work. THANK YOU! I have been looking around the PullMonkey and RailsForum sites but could not find any examples on how to link to a database (except for the old jackster example. For example I have the following columns in results table
(student_name, subject, test_score)
Values
(’Jack’, ‘History’, 85), (’Jill’, ‘History’, 90); etc
In ResultsController:
def index
@results = Result.find(:all)
@graph = open_flash_chart_object(600,300,"/test_it/graph_code")
end
def graph_code
# what goes here?
#
end
Any help is greatly appreciated
Thanks
Archie (newbie)
@Archie Smuts - Great, glad the plugin worked for you.
I posted a database example for you to at least get started with - http://pullmonkey.com/2008/7/25/using-a-database-to-populate-an-open-flash-chart-graph
Hope that helps.
Hi,
I keep getting:
"Open Flash Chart
IO ERROR
Loading test data
Error #2032"
Any idea how to debug that ?
Hi,
I keep getting:
"Open Flash Chart
IO ERROR
Loading test data
Error #2032"
Any idea how to debug that ?
@jetienne - That usually means that the data you are pointing to is invalid, either missing or not json. If you need more help, you can post what you have.
This is great! The demo works wonderfully in FireFox 3 on mac os 10.5.4, but Safari 4 dev preview throws:
TypeError: Undefined value swfobject.js (line 5)
No me puedo hacer.. alguien habla espaƱol????? I cannot do!! Help! The graphs are not displayed
Beautiful! Works perfectly in Safari 3 on Mac OS 10.5.4.
Thanks
Till
Wow, that is extremely clean. Thanks for doing this, it’s an excellent contribution.
It doesn’t look like tool tips are interpreted yet, though I see them coming across in the json. I’ll be keeping an eye on this project - it’s definitely how I’d like to be putting charts on our app.
@Stu - The tooltips were not working. Sorry about that, I fixed it and put up an example - http://pullmonkey.com/2008/7/28/open-flash-chart-ii-multi-bar-graph-with-tooltips
@Brad - Thanks for the heads up. I do not have safari 4, only 3 at this time. I did a little bit of research and the error pointed to a problem in webkit … could be possible? For now it works in FF, IE, and Safari 3, I will see about getting Safari 4. Thanks again.
Thanks a lot for all ! Could you please put an example for pie charts ?
@Chipster - here is a pie chart example - http://pullmonkey.com/2008/7/29/open-flash-chart-ii-pie-chart
Can I get an example for a Horizontal Bar? I am not able to figure out the left, right parameters in the constructor and the constructor itself doesn’t seem to do anything with those parameters.
i accumulate all the errors :/
Plugin not found: ["git://github.com/pullmonkey/open_flash_chart.git"]
it’s normal ?
After perseverance i have the same problem of jetienne!
the error :
Open Flash Chart
IO ERROR
Loading test data
Error #2032
But i have follow exactly this exemple for test your plugin…
the controleur : "migrate_controller.rb"
class MigrateController < ApplicationController
def view
@graph = open_flash_chart_object(600,300,"/migrate/graph_code")
end
def graph_code
title = Title.new("MY TITLE")
bar = BarGlass.new
bar.set_values([1,2,3,4,5,6,7,8,9])
chart = OpenFlashChart.new
chart.set_title(title)
chart.add_element(bar)
render :text => chart.to_s
end
end
the view : "view.html.erb"
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
<%= @graph %>
can you tell me my errors ?
@Mukund - Your example is up - http://pullmonkey.com/2008/7/30/open-flash-chart-ii-horizontal-bar-graph I had to add the HBarValue you class and the constructor to handle left and right. Thanks for bringing this to my attention. So you will need the latest plugin code.
@Victor - you may be behind a firewall that does not allows access to the git port. You may also do this:
script/plugin install http://github.com/pullmonkey/open_flash_chart.git, with port 80 instead.
Also, can you post the outcome of navigating your browser to http://your_domain/migrate/graph_code
This will show you the errors if you are getting any.
Thanks.
@Victor I had the same problem i resolved by replacing in view :
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
by :
<% javascript_include_tag "swfobject" %>
Sorry, i meaned replacing the original " standard " javascript file declaration by rails tag. Hope it could help
so, first
@Charlie with the port 80 it’s ok for the plugin
@Chipster : Thx for the
<% javascript_include_tag "swfobject" %> witch avoid me to set all the code of swfobject.js in the view :p
and to finish @charlie : always the same error on load the flash picture after the gif loading:
Open Flash Chart
IO ERROR
Loading test data
Error #2032
when i set directly : http://localhost:3000/migrate/graph_code the browser return me : {"elements": [{"values": [1, 2, 3, 4, 5, 6, 7, 8, 9], "type": "bar_glass"}], "title": {"text": "MY TITLE"}}
is it normal ?
a moment i have think, i have the solution because redmine with a plugin need a permission for the all the methode define in the controleur (in the init.rb)
and i have put the permission for view and i have forgotten for the graph_code but after set … always the same error :/
@Victor -
1) Right you should definitely put the javascript in the header not just the view.
2) When going to http://localhost:3000/migrate/graph_code you are looking at the JSON that is produced and my JSON looks the same as yours (just different order, which doesn’t matter):
{"title": {"text": "MY TITLE"}, "elements": [{"type": "bar_glass", "values": [1, 2, 3, 4, 5, 6, 7, 8, 9]}]}
3) Do you have the right open-flash-chart.swf from the assets directory of the plugin?
4) Can you post the relevant flash object html that is produced?
Thanks.
Charlie - would you mind providing a recipe/howto for creating line graphs? I have followed your previous example for ofc version 1, and I get blank results in my view. When I try to explicitly put in object tags I get an Error #2032. Here is the output from my view:
<html>
<head>
<script src="/javascripts/swfobject.js?1217527916" type="text/javascript"></script>
</head>
<body>
<div id="flash_content_1217541259.1793"></div>
<script type="text/javascript">
swfobject.embedSWF("/test-it/open-flash-chart.swf", "flash_content_1217541259.1793", "600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Ftest_it%2Fextra_tt"});
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="300" id="chart_1217541259.17927" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="/test-it/open-flash-chart.swf?data=%2Ftest_it%2Fextra_tt" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<embed src="/test-it/open-flash-chart.swf?data=%2Ftest_it%2Fextra_tt" quality="high" bgcolor="#FFFFFF" width="600" height="300" name="chart_1217541259.17927" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="chart_1217541259.17927" />
</object>
</noscript>
</body>
</html>
sorry, here is my output from my view:
<code>
<html>
<head>
<script src="/javascripts/swfobject.js?1217527916" type="text/javascript"></script>
</head>
<body>
<div id="flash_content_1217541259.1793"></div>
<script type="text/javascript">
swfobject.embedSWF("/test-it/open-flash-chart.swf", "flash_content_1217541259.1793", "600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Ftest_it%2Fextra_tt"});
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="300" id="chart_1217541259.17927" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="/test-it/open-flash-chart.swf?data=%2Ftest_it%2Fextra_tt" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<embed src="/test-it/open-flash-chart.swf?data=%2Ftest_it%2Fextra_tt" quality="high" bgcolor="#FFFFFF" width="600" height="300" name="chart_1217541259.17927" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="chart_1217541259.17927" />
</object>
</noscript>
</body>
</html>
</code>
when i am in the case of the flash object is loaded ,this is the html return :
view.html //
<object id="flash_content_1217574332.47648" height="300" width="600" type="application/x-shockwave-flash" data="/open-flash-chart.swf" style="visibility: visible;">
<param name="flashvars" value="data-file=%2Fmigrate%2Fgraphcode"/>
</object>
<script type="text/javascript">
1
2 swfobject.embedSWF("/open-flash-chart.swf", "flash_content_1217574332.47648", "600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Fmigrate%2Fgraphcode"});
3
</script>
<noscript> <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="300" id="chart_1.217574332476786e+9" align="middle"> <param name="allowScriptAccess" value="sameDomain" /> <param name="movie" value="/open-flash-chart.swf?data=%2Fmigrate%2Fgraphcode" /> <param name="quality" value="high" /> <param name="bgcolor" value="#FFFFFF" /> <embed src="/open-flash-chart.swf?data=%2Fmigrate%2Fgraphcode" quality="high" bgcolor="#FFFFFF" width="600" height="300" name="chart_1.217574332476786e+9" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="chart_1.217574332476786e+9" /> </object> </noscript>
when i am in the case of the flash object is loaded ,this is the html return :
view.html //
<object id="flash_content_1217574332.47648" height="300" width="600"
type="application/x-shockwave-flash" data="/open-flash-chart.swf" style="visibility: visible;">
<param name="flashvars" value="data-file=%2Fmigrate%2Fgraphcode"/>
</object>
<script type="text/javascript">
1
2 swfobject.embedSWF("/open-flash-chart.swf", "flash_content_1217574332.47648",
"600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Fmigrate%2Fgraphcode"});
3
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"
width="600" height="300" id="chart_1.217574332476786e+9" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="/open-flash-chart.swf?data=%2Fmigrate%2Fgraphcode" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<embed src="/open-flash-chart.swf?data=%2Fmigrate%2Fgraphcode"
quality="high" bgcolor="#FFFFFF" width="600" height="300"
name="chart_1.217574332476786e+9" align="middle" allowScriptAccess="sameDomain"
type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"
id="chart_1.217574332476786e+9" /> </object> </noscript>
I’m sorry for the duplicate. but your comment listenner don’t display all the html code .
i set it in this file :
http://www.neufgiga.com/index.php?m=c9ae77e8&a=dc18f91e&share=LNK68154892bb12a8a0c
@andrew - here is a line graph example - http://pullmonkey.com/2008/8/1/open-flash-chart-ii-line-graph
To insert HTML/ruby/other code into the comments, you can do this:
<filter:code attributes=lang="ruby">
<filter:code attributes=lang="ruby">
# change the attributes lang from ruby to html or whatever you want.
# Put your stuff here
# and for the line below, get rid of the space
< /filter:code>
</filter:code>
That should do it …
So here is Victor’s HTML:<filter:code attributes=lang="ruby"> view.html //
<object id="flash_content_1.217574723488243e+9" height="300" width="600" type="application/x-shockwave-flash" data="/open-flash-chart.swf" style="visibility: visible;">
<param name="flashvars" value="data-file=%2Fmigrate%2Fgraphcode"/>
</object>
<script type="text/javascript">
1
2 swfobject.embedSWF("/open-flash-chart.swf", "flash_content_1.217574723488243e+9", "600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Fmigrate%2Fgraphcode"});
3
</script>
<noscript> <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="300" id="chart_1217574723.48741" align="middle"> <param name="allowScriptAccess" value="sameDomain" /> <param name="movie" value="/open-flash-chart.swf?data=%2Fmigrate%2Fgraphcode" /> <param name="quality" value="high" /> <param name="bgcolor" value="#FFFFFF" /> <embed src="/open-flash-chart.swf?data=%2Fmigrate%2Fgraphcode" quality="high" bgcolor="#FFFFFF" width="600" height="300" name="chart_1217574723.48741" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="chart_1217574723.48741" /> </object> </noscript>
// </filter:code>
And for comparison with Victor’s here is what I get:
<filter:code attributes=lang="ruby"><div id="flash_content_1217006545.4401"></div>
<script type="text/javascript">
swfobject.embedSWF("/projects/open-flash-chart.swf", "flash_content_1217006545.4401", "600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Fprojects%2Fopen_flash_chart2%2Fbasic_starter"});
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="300" id="chart_1217006545.44007" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="/projects/open-flash-chart.swf?data=%2Fprojects%2Fopen_flash_chart2%2Fbasic_starter" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<embed src="/projects/open-flash-chart.swf?data=%2Fprojects%2Fopen_flash_chart2%2Fbasic_starter" quality="high" bgcolor="#FFFFFF" width="600" height="300" name="chart_1217006545.44007" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="chart_1217006545.44007" />
</object>
</noscript></filter:code>I notice a few things:
1) You are missing the div that the graph goes in to
2) Numbers appear in your javascript
3) You have two objects in your html, I have one
Can you post your controller code for both the index and the graph_code? Are you using the plugin?
In the graphs of horizontal bars can they add lines on every bar? To do graphs Gantt? Or already there exists inside the plugin a way of doing graphs Gantt?
@Cecci - can you give me an example of what you are after? Do you mean lines in terms of a grid or lines connecting each bar? Or something different? Send me a link to an image that you would like to duplicate.
I get the 2032 as well.
If I break at the end of the action and call chart.to_s I get
SystemStackError: stack level too deep
from C:/railapps/picnicdog/vendor/plugins/open_flash_chart/lib/open_flash_chart.rb:23:in `to_s’
from C:/railapps/picnicdog/vendor/plugins/open_flash_chart/lib/open_flash_chart.rb:23:in `to_json’
from C:/railapps/picnicdog/vendor/plugins/open_flash_chart/lib/open_flash_chart.rb:23:in `to_s’
from C:/railapps/picnicdog/vendor/plugins/open_flash_chart/lib/open_flash_chart.rb:23:in `to_json’
from C:/railapps/picnicdog/vendor/plugins/open_flash_chart/lib/open_flash_chart.rb:23:in `to_s’
from C:/railapps/picnicdog/vendor/plugins/open_flash_chart/lib/open_flash_chart.rb:23:in `to_json’
from C:/railapps/picnicdog/vendor/plugins/open_flash_chart/lib/open_flash_chart.rb:23:in `to_s’
from C:/railapps/picnicdog/vendor/plugins/open_flash_chart/lib/open_flash_chart.rb:23:in `to_json’
from C:/railapps/picnicdog/vendor/plugins/open_flash_chart/lib/open_flash_chart.rb:23:in `to_s’
from C:/railapps/picnicdog/vendor/plugins/open_flash_chart/lib/open_flash_chart.rb:23:in `to_json’
from C:/railapps/picnicdog/vendor/plugins/open_flash_chart/lib/open_flash_chart.rb:23:in `to_s’
from C:/railapps/picnicdog/vendor/plugins/open_flash_chart/lib/open_flash_chart.rb:23:in `to_json’
from C:/railapps/picnicdog/vendor/plugins/open_flash_chart/lib/open_flash_chart.rb:23:in `to_s’
from C:/railapps/picnicdog/vendor/plugins/open_flash_chart/lib/open_flash_chart.rb:23:in `to_json’
from C:/railapps/picnicdog/vendor/plugins/open_flash_chart/lib/open_flash_chart.rb:23:in `to_s’
from C:/railapps/picnicdog/vendor/plugins/open_flash_chart/lib/open_flash_chart.rb:23:in `to_json’
… 10934 levels…
from c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.4-x86-mswin32-60/lib/mongrel/command.rb:212:in `run’
from c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.4-x86-mswin32-60/bin/mongrel_rails:281
from C:/railapps/picnicdog/vendor/rails/activesupport/lib/active_support/dependencies.rb:488:in `load’
from C:/railapps/picnicdog/vendor/rails/activesupport/lib/active_support/dependencies.rb:488:in `load’
from C:/railapps/picnicdog/vendor/rails/activesupport/lib/active_support/dependencies.rb:342:in `new_constants_i
n’
from C:/railapps/picnicdog/vendor/rails/activesupport/lib/active_support/dependencies.rb:488:in `load’
from C:/railapps/picnicdog/vendor/rails/railties/lib/commands/servers/mongrel.rb:64
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
from C:/railapps/picnicdog/vendor/rails/activesupport/lib/active_support/dependencies.rb:495:in `require’
from C:/railapps/picnicdog/vendor/rails/activesupport/lib/active_support/dependencies.rb:342:in `new_constants_i
n’
from C:/railapps/picnicdog/vendor/rails/activesupport/lib/active_support/dependencies.rb:495:in `require’
from C:/railapps/picnicdog/vendor/rails/railties/lib/commands/server.rb:39
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
Any advice?
@Gallo, would you mind posting your code and I will see if I can help.
My code is exactly the same except I have
@graph = open_flash_chart_object(600,300,"/weight/graph_code")
as my controller is the "weight" controller.
If I break right before the render call and I look at the chart object it appears fine. See below.
irb(#<WeightController:0xa772914>):001:0> chart
=> #<OpenFlashChart:0xa6da448 @elements=[#<BarGlass:0xa6da4e8 @values=[1, 2, 3, 4, 5, 6, 7, 8, 9], @type="bar_glass">],
@title=#<Title:0xa6da4fc @text="MY TITLE">>
irb(#<WeightController:0xa772914>):002:0>
When I call chart.to_s I get the above error in my previous post.
Json is working. I test converted some Active Record Objects to_json and that worked fine.
Cheers
@Gallo - you can just call chart.to_json instead if that works for you. That way you don’t get in the loop with to_s.
Hello, might you see this link to see what it wanted to do? It is a graph gantt. I it must represent of equal way in code ruby and the plugin
http://www.kabytes.com/wp-content/uploads/2007/04/gantt-project.jpg
The information must be of a database. I wait could help me, thank you.
Hey, i followed the install instruction, but the data is not rendering, only:
C:\Users\John\Documents\flash\svn\data-files\data-14.txt
appears inside the graph object.
Any ideas?
My fault, had an old version of open-flash-chart.swf in my public folder!
@Cecci - I have not found a way to do what you are asking with the lines and such. I will let you know if I find anything. You might want to contact monk.e.boy - http://teethgrinder.co.uk/open-flash-chart-2/ as he is responsible for the open-flash-chart.swf, and see what he says about getting gantt charts. I think he will appreciate the suggestion.
my controler :
<filter:code attributes=lang="ruby">
def view
@graph = open_flash_chart_object(600,300,"/migrate/graphcode")
end
def graphcode
title = Title.new("MY TITLE")
bar = BarGlass.new
bar.set_values([1,2,3,4,5,6,7,8,9])
chart = OpenFlashChart.new
chart.set_title(title)
chart.add_element(bar)
render :text => chart.to_s
end
< /filter:code>
i don’t understand why i have this error …
my controler :
<filter:code attributes=lang="ruby">
def view
@graph = open_flash_chart_object(600,300,"/migrate/graphcode")
end
def graphcode
title = Title.new("MY TITLE")
bar = BarGlass.new
bar.set_values([1,2,3,4,5,6,7,8,9])
chart = OpenFlashChart.new
chart.set_title(title)
chart.add_element(bar)
render :text => chart.to_s
end
</filter:code>
i don’t understand why i have this error …
@Victor - here is one thing you should try:<filter:code attributes=lang="ruby">def view
@graph = open_flash_chart_object(600,300,"/migrate/graphcode")
end
def graphcode
render :text => %’{"title": {"text": "MY TITLE"}, "elements": [{"type": "bar_glass", "values": [1, 2, 3, 4, 5, 6, 7, 8, 9]}]}’
end
</filter:code>This should help us figure out where the problem lies. My guess at this point is that you need the latest swf file and it needs to be placed in RAILS_ROOT/public.
this is my html code with your controlor :
<filter:code attributes=lang="ruby">
<div id="flash_content_1.218005931023648e+9"></div>
<script type="text/javascript">
swfobject.embedSWF("/open-flash-chart.swf", "flash_content_1.218005931023648e+9", "600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Fmigrate%2Fgraphcode"});
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="300" id="chart_1.218005931022503e+9" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="/open-flash-chart.swf?data=%2Fmigrate%2Fgraphcode" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<embed src="/open-flash-chart.swf?data=%2Fmigrate%2Fgraphcode" quality="high" bgcolor="#FFFFFF" width="600" height="300" name="chart_1.218005931022503e+9" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="chart_1.218005931022503e+9" />
</object>
</noscript>
</filter:code>
and i think i have the latest swf (size : 274Ko)
and i always the error #2032.
so after test with i delete the swf of my public directory , i have always the same error , we are on the good way …
perhaps my plugin don’t take the swf in the public directory, perhaps i will set at a another directory…
don’t forget it’s a plugin witch take your plugin for graph … perhaps it’s the solution
i don’t understand … if i delete the swf on the public directory , i have a flash loading … follow by my error …
And if i edit in your plugin the "base=/" at the display i don’t have any flash loading … :/
:$
@Victor - interesting. Do you have javascript enabled? Try removing one or the other section. I.e., remove the script javascript portion or the noscript portion and let me know the results.
So first for my motivation i have test the plugin in a project directly … YES it’s works, lol
i’m not a looser…
with my plugin i have make your test , if i remove the javascript portion or the noscript portion ( in your open_flash_chart_object.rb if i have understand has you want)i haven’t a swf loaded :/
@Victor - perfect, so it works in a project, may I ask how you were using it before using the "plugin in a project directly?"
And for the test, I really just thought you could bypass the use of the plugin (trying to narrow down the problem) and just copy your html (that you provided above) directly in to your view then remove one (javascript) or the other (noscript) portion and see how it goes.
In your opinion, what’s the best movie ever created?
OOps
i had forget to re make the swf in the public directory for the test witch remove javascript portion or noscript
so i re test: if the javascript are removed , no swf are loaded , but if i remove the noscript portion tht swf are loaded and the error are display :/
I’m sorry for my bad manipulation witch reappraisal the possible solution
@Victor - let’s start simple:
Browse to http://yourdomain/test_it/test_one - you should see the JSON that we manually entered
1) Create a controller (TestIt):
./script/generate controller test_it
2) Add the action test_one() to the controller
3) Copy this code to test_one():<filter:code attributes=lang="ruby">def test_one
render :text => %’{"title": {"text": "MY TITLE"}, "elements": [{"type": "bar_glass", "values": [1, 2, 3, 4, 5, 6, 7, 8, 9]}]}’
end</filter:code>
4) Make sure open-flash-chart.swf is in your RAILS_ROOT/public directory
5) Make sure swfobject.js is in your RAILS_ROOT/public/javascripts directory
6) Note: You don’t need the plugin installed at all for this, since we are creating the JSON by hand.
7) Create a view (index.html.erb) under RAILS_ROOT/app/views/test_it/ like this:<filter:code attributes=lang="ruby"><div id="flash_content"></div>
<script type="text/javascript">
swfobject.embedSWF("/open-flash-chart.swf", "flash_content", "600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Ftest_it%2Ftest_one"});
</script></filter:code>
9) Browse to http://yourdomain/test_it - you should see glass bar graphs
Let me know.
@Victor - also, some good things to know:
1) What browser?
2) What OS?
3) Shouldn’t matter for the example above, but what versions of rails and ruby?
@Charlie
For your test , i make a new project or i test it on my plugin of redmine ?
so 1/FF 3
2/Windows XP
3/ruby 1.8.6 & rails 2.0.2
@Victor - Both - in a new project just as a base case then in your plugin of redmine.
Charlie,
If I insert the json manually in the graph_code method the chart shows fine.
Hence the problem is the call that converts the openflashchart object to json.
What are you using to convert it to Json. I have the json gem installed as one of my other plugins requries it.
Thoughts?
so first: in a new project , i have the JSON that we manually entered but i shouldn’t see glass bar graphs for http://yourdomain/test_it :/
in my plugin, i always have the JSON but for the graph i have this error : ArgumentError in MigrateController#index
A copy of ApplicationController has been removed from the module tree but is still active!
RAILS_ROOT: D:/Service/Profiles/vleboucher.BDOM/Mes documents/NetBeansProjects/Redmine/Victor/Redmine
Application Trace | Framework Trace | Full Trace
vendor/rails/activesupport/lib/active_support/dependencies.rb:237:in `load_missing_constant’
vendor/rails/activesupport/lib/active_support/dependencies.rb:469:in `const_missing’
app/controllers/application.rb:35:in `user_setup’
:1:in `start’
@Gallo - I am just using obj.to_json. You should not require a plugin to do this. So what is the name of the plugin you are using to JSON?
@Victor - This may help - http://www.ruby-forum.com/topic/134839 it is a few months old, but seems to fit your problem for redmine.
As far as your first statement that you should not see the glass bar graph - could you clarify what you mean for me?
I haven’t find a help in your URL
what do you want i clarify ? i don’t understand do you want :/
@Victor - Sorry, it was worth a shot.
And … I need clarification on this:
"so first: in a new project , i have the JSON that we manually entered but i shouldn’t see glass bar graphs for http://yourdomain/test_it :/"
It seems to me that you are saying that you entered in JSON manually and do not think that you should see the graph. But you actually should see the graph with just the JSON itself.
I have followed your recipe here, except that the automatic download/install didnt work so I had to download manually and do :
rake open_flash_chart_2:install
(The mentioned .js and .swf files above seems to have appeared in their correct locations)
When trying to acess my rails application in the web browser I get the following error:
undefined method `open_flash_chart_object’ for #<TestController:0×37c8c1c>
app/controllers/test_controller.rb:4:in `index’
Do you have any idea what might be causing this error?
Do I need to require a gem somewhere in my code?
(I have installed the json and haml gems which where mentioned somewhere to be required)
I think you can disregard my last post. Amazingly, it seems like I’ve installed someone else’s flash chart rails plugin (korin), and then navigated to your page for tutorials on using it… :/
Anyway, the automatic git install simply isnt working for me (fatal: unable to connect a socket), so I manually downloaded the zip file from the github, unzipped it to the plugins folder and copied the two mentioned files to their destinations manually. I again tried to run the application, and I got the following error:
undefined local variable or method `protocol’ for #<TestController:0×2c34748>
So I removed the mentions of #protocol in the open_flash_chart_object.rb file, ran the application again and the chart finally was displayed in all its beauty!
So the moral of it might be that it would be very nice if you would also make a recipe for installing open flash chart II using a manual download.
Anyway, thanks for the great work!
@Christopher - you may be behind a firewall and just need to replace git://github… with http://github... so that you install over port 80. Give that a shot.
@Christopher - I removed the protocol variable on accident
Added it back, thanks for the catch.
Hi Charlie, thanks a lot for your work.
I’ve tried getting the first graph to show up, but I’m not able to. I don’t get anything on the browser, and there’s a "Done, with errors" in Internet Exploder, and the info is:
Line: 6
Char: 6921
Error: Invalid argument.
Code: 0
URL: http://localhost:3002/main
There’s no error/warning messages in the web browser’s output.
Any ideas?
My controller is ‘main’:
<filter:code attributes=lang="ruby">
class MainController < ApplicationController
def index
@graph = open_flash_chart_object(600,300,"/main/graph_code")
end
def graph_code
title = Title.new("My test")
bar = BarGlass.new
bar.set_values([1,2,3,4,5,6,7,8,9])
chart = OpenFlashChart.new
chart.set_title(title)
chart.add_element(bar)
render :text => chart.to_s
end
end
</filter:code>
view ‘main/index.html.erb’:
<filter:code attributes=lang="html">
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
<%= @graph %>
</filter:code>
Generated HTML:
<filter:code attributes=lang="html">
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
<div id="flash_content_MS4yMTg4MzU4NTk2NDk3MDVlKzklMkZtYWluJTJGZ3JhcGhfY29kZQ=="></div>
<script type="text/javascript">
swfobject.embedSWF("/open-flash-chart.swf", "flash_content_MS4yMTg4MzU4NTk2NDk3MDVlKzklMkZtYWluJTJGZ3JhcGhfY29kZQ==", "600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Fmain%2Fgraph_code"});
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="300" id="chart_MS4yMTg4MzU4NTk2NDk3MDVlKzklMkZtYWluJTJGZ3JhcGhfY29kZQ==" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="/open-flash-chart.swf?data=%2Fmain%2Fgraph_code" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<embed src="/open-flash-chart.swf?data=%2Fmain%2Fgraph_code" quality="high" bgcolor="#FFFFFF" width="600" height="300" name="chart_MS4yMTg4MzU4NTk2NDk3MDVlKzklMkZtYWluJTJGZ3JhcGhfY29kZQ==" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="chart_MS4yMTg4MzU4NTk2NDk3MDVlKzklMkZtYWluJTJGZ3JhcGhfY29kZQ==" />
</object>
</noscript>
</filter:code>
Accessing http://localhost:3002/main/graph_code i get what seems to be the appropiate JSON:
<filter:code attributes=lang="html">
{"elements": [{"values": [1, 2, 3, 4, 5, 6, 7, 8, 9], "type": "bar_glass"}], "title": {"text": "My test"}}
</filter:code>
@Totem - The JSON is correct, so the plugin is working correctly. It seems that the swfobject.js file is causing the problem. I would test your application in Firefox if you can, FF generally gives pretty decent javascript error messages. That may help lead us to a solution.
@charlie, I do not know why I didn’t try FF before, but now that I tried it (FF 3.0), it works without a problem. However, IE 7 gives the error provided above.
Any ideas on how to get it to work with IE? Unfortunately, it is a requirement for my project. Should I try using IE 8 (beta) that has some debugging features in it to try to figure this out?
@Totem - well I was hoping FF would shed some light for you … I have one more thing for you to try -
1) Go here - http://www.macromedia.com/software/flash/about/
– or –
Right click your mouse over where the flash graph should be and see what is says here "About Macromedia Flash Player X"
2) See what version you have, if you right clicked then what is X? …
3) If you do not have version 9 then Install flash player 9
So what I am assuming here, is that you have flash player 6 or at least something older than 9. Let me know.
Accessing http://www.macromedia.com/software/flash/about/ gives the following
IE has: 9,0,115,0 installed
FF has: 9,0,124,0 installed
I then upgraded IE, and now:
IE has: 9,0,124,0 installed
However, the error message is still the same in IE.
@Totem - do you see graphs if you go here - http://pullmonkey.com/projects/open_flash_chart2 or do you still get the same error?
That’s the weird thing, I’m able to see the charts on pullmonkey on both FF and IE, but I’m only able to see the chart for my RoR app on FF. IE gives that error about invalid argument.
IE and FF return the right JSON
@Totem - see what you get when you use this swfobject - http://pullmonkey.com/projects/javascripts/swfobject.js
That is the one I am using. Yours may have gotten corrupted or something.
Same thing. FF is fine, IE gives the error.
I’m surprised that no one else is having a similar problem.
@Totem - I checked the OFC forums for you - http://sourceforge.net/forum/?group_id=201148 but nothing too helpful, however other people are having the same problem.
It’s kind of weird that I’m able to see the charts on the pullmonkey.com site in IE, but not my local copy. Could you zip up the swf file so that I can download it and try it out locally? Also, if you already have the RoR testing_ofc_2 project working and as you mentioned in the tutorial, could you zip it up and I can try running it locally?
thanks for your help
Hey Charlie, I’ve got an interesting piece of information. When I hit localhost:3000/main with FF, I get my breakpoint hit in def graph_code. However, when I try hitting it with IE (I tried reloading/refreshing, etc) def index gets hit, but NOT def graph_code.
Not that the following log is extremely useful, but here’s the log from the web server:
IE:
127.0.0.1 - - [18/Aug/2008:14:55:42 CDT] "GET /main HTTP/1.1" 200 1400
- -> /main
127.0.0.1 - - [18/Aug/2008:14:55:51 CDT] "GET /javascripts/swfobject.js HTTP/1.1" 304 0
http://localhost:3000/main -> /javascripts/swfobject.js
FireFox:
127.0.0.1 - - [18/Aug/2008:14:56:21 CDT] "GET /main HTTP/1.1" 200 1400
- -> /main
127.0.0.1 - - [18/Aug/2008:14:56:27 CDT] "GET /javascripts/swfobject.js HTTP/1.1" 304 0
http://localhost:3000/main -> /javascripts/swfobject.js
127.0.0.1 - - [18/Aug/2008:14:56:27 CDT] "GET /open-flash-chart.swf HTTP/1.1" 304 0
http://localhost:3000/main -> /open-flash-chart.swf
127.0.0.1 - - [18/Aug/2008:14:56:27 CDT] "GET /main/graph_code HTTP/1.1" 304 0
- -> /main/graph_code
@Totem - wow that is interesting … any browser caching going on with your site specifically? Seems that if IE does not ask for it then it has it? Try clearing your cache and go ahead and start your server on port 3001 or something other than 3000, just for a test to see what we get. Sorry if it seems like I am running out of stuff … really haven’t been able to duplicate this problem for you. I will zip this example up and send it your way tomorrow morning. If you notice that I forget, just drop me a line at charlie at pullmonkey dot com and put "open flash chart" in the subject.
@Totem - the tar.gz is available here - http://pullmonkey.com/projects/open_flash_chart2/
There is a download link after the Sample Use heading.
http://pullmonkey.com/projects/open_flash_chart2/test_ofc_2.tar.gz
Works for me in IE 6+, FF 2+ and Safari. Hope it works for you.
I’m getting the same Stack-Error as Gallo, seems like to_json calls to_s and this is causing the infinite loop.
I’m not using Rails, and required the gem ‘json’ ā which one do I need?
Just in case someone else has this problem: instead of the gem ‘json’ you need to require ‘activesupport’
Hello
thx for your great work
I noticed that the plugin works well with webrick or mongrel (script/server) but doesn’t with apache through phusion 2.0.2.
Any idea ?
Thx again
@renoo - No ideas really, what is the problem? What is the HTML that is displayed? What is the JSON that is produced? Let me know.
Hello,
I have a problem in relation to execution. When I run my application (with the code that is on the site), it does nothing without any error.
I have to refresh 20 times the page on my browser and I see the chart.
What is the problem?
thank you
thank you
I have tried to create custom tooltips in LineDots like in this example http://pullmonkey.com/projects/open_flash_chart/view_source_code/extra_tt .
In the example you use "Elem.add_data_tip(value, tip)" for create each of them, but in my current project i can“t use this instruction. When i doit i receive a message from the method_mysing method.
Note:
I have cloned the github Version project for Open Flash Chart Plugin.
Nice Work Man, Thanks!
Pd: Sorry for my English
@Charlie, thanks for all the help on the problem of not loading in IE. I downloaded the file you uploaded, and I noticed that you’re using Rails 2.1, I’m on 2.0.2. After doing some minor changes to get it to run on 2.0.2, the same problem happened. IE 7 fails, and FF 3.0.x works fine. Maybe I just need to try it on 2.1, but I believe there’s no InstantRails (yes, I’m on windows) for Rails 2.1 yet.
On a similar note, now that I’m progressing with FF, I’m trying to update the graph depending on a drop down that the user has selected - Ajax, but I’m unable to get the ‘graph_code’ function called and update the <div>. I believe part of the problem is that the ‘id’ of the <div> changes everytime. Is there a sample that shows how to update the graph using AJAX?
(I know that the this controller is getting executed for sure. Also, see that the controller is calling the "graph_code" function twice, I tried all kinds of tricks, but no avail, I don’t see graph_code being executed)
Controller code:
<filter:code attributes=lang="ruby">
def selection_changed
graph_code
@graph = open_flash_chart_object(800,600,"/main/graph_code")
end
</filter:code>
thanks
BTW, where there’s something missing from my previous post, I typed < div > without the spaces, but it got chewed…
Please ignore my previous message about the problem with AJAX. I wrapped <%= graph %> in a specific < div > and put it in a partial and everything is fine now.
thanks
(Still need to figure this problem with it not working in IE 7 though…)
Am I the only one seeing no result at all?
When i open http://localhost:3000/test_it, in the terminal, i can see
Processing TestItController#index (for 127.0.0.1 at 2008-08-25 10:47:27) [GET]
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo
SGFzaHsABjoKQHVzZWR7AA==–c687de75d19d1a97bb4ffd54eea6a56b856016a2
Parameters: {"action"=>"index", "controller"=>"test_it"}
Rendering test_it/index
Completed in 0.00224 (446 reqs/sec) | Rendering: 0.00045 (20%) | DB: 0.00000 (0%) | 200 OK [http://localhost/test_it]
but nothing happened in my safari. Just empty.
OK. i THINK I have the same question as Nanaz.
I used the sample test_one function and all i can see from
http://localhost:3000/test_it/test_one
is
{"title": {"text": "MY TITLE"}, "elements": [{"type": "bar_glass", "values": [1, 2, 3, 4, 5, 6, 7, 8, 9]}]}
In text. is it right?
This is the output from my safari/firefox 3.0.
I can’t see any flash. Can I get help?
<filter:code attributes=lang="ruby">
<div id="flash_content"></div>
<script type="text/javascript">
swfobject.embedSWF("/open-flash-chart.swf", "flash_content", "600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Ftest_it%2Ftest_one"});
</script>
</filter:code>
<filter:code attributes=languag="ruby">
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
<div id="flash_content_MTIxOTY4OTkwMy42MjglMkZ0ZXN0X2l0JTJGZ3JhcGhfY29kZQ=="></div>
<script type="text/javascript">
swfobject.embedSWF("/open-flash-chart.swf", "flash_content_MTIxOTY4OTkwMy42MjglMkZ0ZXN0X2l0JTJGZ3JhcGhfY29kZQ==", "600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Ftest_it%2Fgraph_code"});
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="300" id="chart_MTIxOTY4OTkwMy42MjglMkZ0ZXN0X2l0JTJGZ3JhcGhfY29kZQ==" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="/open-flash-chart.swf?data=%2Ftest_it%2Fgraph_code" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<embed src="/open-flash-chart.swf?data=%2Ftest_it%2Fgraph_code" quality="high" bgcolor="#FFFFFF" width="600" height="300" name="chart_MTIxOTY4OTkwMy42MjglMkZ0ZXN0X2l0JTJGZ3JhcGhfY29kZQ==" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="chart_MTIxOTY4OTkwMy42MjglMkZ0ZXN0X2l0JTJGZ3JhcGhfY29kZQ==" />
</object>
</noscript>
</filter:code>
This is other output from other machine, your test_it example. Still I am not seeing anything other than a blank page
This may be a silly question, but I’d like for graph_code to take parameters so that I can pass in the title, and other items that are specific to each graph that I’m rendering. If I try to change graph_code to take parameters, it barfs…
What’s the best way to do this?
thank you
@Totem - that is a good question. graph_code is an action and does not take parameters in the conventional ruby way. You will want to use the params variable and do something like this:<filter:code attributes=lang="ruby">
def graph_code
title = Title.new(params[:title]) #grab it from the request parameters
#or
title = Title.new(@title) # grab it from an instance variable, for example, set in a before_filter.
…
end</filter:code>
@hhh - Do you have javascript enabled? Can you see my graphs? Your JSON output looks right.
@Miguel Ćngel - I think it is because I didn’t require tooltip.rb in the init.rb of the plugin on github - get the latest version and let me know how it goes.
The only problem is that I’m calling graph_code from another action. Basically, whenever the user chooses a different selection from the drop down, it calls action ‘def selection_changed’ with some params[], which then gathers data from the database, and then calls ‘def graph_code’ through the call:
@graph = open_flash_chart_object(800,600,"/main/graph_code")
so, I can’t use params or @var from ‘def selection_changed’. Currently, I’m forced to pass it through a global (dirty) or session[] (dirty too)…
thanks
@Charlie
It looks like a Beta 1 has been released. Do we need to get the new .swf and .js or is there updates to the plugin that are needed?
No pressure to get up to date, I know you do this on your spare time and we appreciate your hard work on this.
Cheers!
@Charlie, it looks like there’s no way to setup the title style. In the 1.9.x versions I see:
<filter:code attributes=lang="ruby">
def set_title(title, style=”)
@title = Graph.esc(title)
@title_style = style if style.size > 0
end
def title(title, style=”)
set_title(title, style)
end
</filter:code>
but in version 2, I only see:
<filter:code attributes=lang="ruby">
class Title < OpenFlashChart
def initialize(text=”)
@text = text
end
end
</filter:code>
any reason for this?
thanks!
@Charlie, it looks like there’s no way to setup the title style. In the 1.9.x versions I see:
<filter:code attributes=lang="ruby">
def set_title(title, style=”)
@title = Graph.esc(title)
@title_style = style if style.size > 0
end
def title(title, style=”)
set_title(title, style)
end
</filter:code>
but in version 2, I only see:
<filter:code attributes=lang="ruby">
class Title < OpenFlashChart
def initialize(text=”)
@text = text
end
end
</filter:code>
any reason for this?
thanks!
@Totem - I am using some method_missing magic, so the best thing to do when you need to figure out how to use the plugin is to look at the documentation here - http://teethgrinder.co.uk/open-flash-chart-2/title.php
You can set the style like this:
<filter:code attributes=lang="ruby">title = Title.new("SOME TITLE")
title.set_style("{font-size: 20px; color: #A2ACBA; text-align: center;}")</filter:code>Hope that helps.
Hello, I’m having trouble figuring out hot to get the syntax highlighting to work. Here is my plugin install html output for /test_it
<filter:code attributes=lang="html">
<div id="flash_content_MTIyMDQ1MzA0NS41ODEyOSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl"></div>
<script type="text/javascript">
swfobject.embedSWF("/open-flash-chart.swf", "flash_content_MTIyMDQ1MzA0NS41ODEyOSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl", "600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Ftest_it%2Fgraph_code"});
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="300" id="chart_MTIyMDQ1MzA0NS41ODEyOSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="/open-flash-chart.swf?data=%2Ftest_it%2Fgraph_code" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<embed src="/open-flash-chart.swf?data=%2Ftest_it%2Fgraph_code" quality="high" bgcolor="#FFFFFF" width="600" height="300" name="chart_MTIyMDQ1MzA0NS41ODEyOSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="chart_MTIyMDQ1MzA0NS41ODEyOSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" />
</object>
</noscript>
</filter:code>
As you see, I figured out the highlighting at the last moment
So, I see a blank page. Do I need to have db access and pull data from it to see the graph? I was expecting a sample graph.. Thanks so much for a beautiful way to make my work fun this week
Ahh! I had forgotten to copynpaste the js file and put an = (<%= javascript_… %> Works great! Very nice sample graph
Hi, I’m trying to use this as in a model. I’m confused over the ‘url’ parameter in the open_flash_chart_object method. How can I re-write this to use in a model? I need to pass ‘protein’, ‘carbs’, ‘unsaturated_fat’, and ’saturated_fat’ to the graph_code method. Can I do this?
I’m on the clock here. I can make a decent donation if there is a way to make the chart data static.
Here’s my situation..
First, I have several thousand scripted pages, where it seems impossible to access the graph_code method.
<filter:code attributes=lang="ruby">
block_output[0] = <<PAGE_HEADER
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
.
.
.
<!– common name #{header[:common_name]} –>
<!– scientific name #{header[:scientific_name]} –>
<!– manufacturer name #{header[:manufacturer_name]} –>
<script type="text/javascript" src="/javascripts/clientside-trunk-515.compressed.js"></script>
<script type="text/javascript" src="/javascripts/tabs.js"></script>
<link href="/stylesheets/static_page.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="whole_page">
<div class="header">
<div id="nav"></div>
<div class="static permalink panelSet" id="content">
<h1>#{food.description_long}#{header[:common_name]}</h1>
<div id="tabBoxExample">
<ul class="tabSet">
#{links}
</ul>
<div class="panelSet">
<div class="static charts">
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
#{@graph}
</div>
PAGE_HEADER
</filter:code>
Here is the StaticPageController
<filter:code attributes=lang="ruby">
class StaticPageController < ApplicationController
def index
@graph = open_flash_chart_object(600,300,"/static_page/graph_code")
end
def show
if params[:permalink]
@page_url = StaticPage.find_by_permalink(params[:permalink])
raise ActiveRecord::RecordNotFound, "Page not found" if @page_url.nil?
@page = File.read("#{RAILS_ROOT}/public/static_pages/" + params[:permalink])
@graph = open_flash_chart_object(600,300,"/static_page/graph_code")
else
@page = StaticPage.find(params[:id])
end
end
def graph_code
title = Title.new("MY TITLE")
bar = BarGlass.new
bar.set_values([1,2,3,4,5,6,7,8,9])
chart = OpenFlashChart.new
chart.set_title(title)
chart.add_element(bar)
render :text => chart.to_s
end
end
</filter:code>
I need to access this method from the scripted page (which seems to my intermediate skill impossible), or make 7500 static charts. Can you walk me through this? I have flash installed. Maybe I can make a donation and possibly contribute to the design elements. Thank you so much.
@Jesse - no need for a donation. I sent you an email.
I’ll be interested in how this was done too.
Could you share the information?
@Totem - I gave Jesse some advice and we have been working through a couple things. When he gets it all figured out, I will see if he wouldn’t mind doing a guest post or a long comment here for everyone to see.
Hi,
I used previous version of open flash chart with rails 1.2.5. Everything was working fine out there. But when I installed 2.1.0 I am getting the following error:
NoMethodError in controller.
undefined method `open_flash_chart_object’
The plugin is in right place– Vendor/plugins/open_flash_chart. I can see the method too. But rails is unable to detect that. Any clue? I would really appreciate your help because I am kind of stuck.
Thank you.
@Fuad - make sure that the init.rb file exists in RAILS_ROOT/vendor/plugins/open_flash_chart/init.rb. Also, if you haven’t already, restart the application so that the plugin can load.
The init.rb file should look like this - http://github.com/pullmonkey/open_flash_chart/tree/master/init.rb
Great plugin. It worked like a charm on Rails 2.x.
But does it work on Rails 1.2.x ?
I got the following error on Rails 1.2.x :
Open Flash Chart
JSON Parse Error [Bad String]
Error at character 1, line 1:
-2: undefined-1: undefined0: {title: {text: "MY TITLE"}, elements: [{type: "bar_glass", values: [1, 2, 3, 4, 5, 6, 7, 8, 9]}]
@Harry - There is the Rails OFC I plugin that does work with 1.2.x - http://pullmonkey.com/projects/open_flash_chart
I have same problem with totem which is about pass the parameter to graph_code
I’ve tried to use static variable and global variable but failed
And I don’t know why it fails. (the variance vias became ‘0′)
I do like this : test_it_controller => index.erb.html => test_it_controller => view.erb.html
In web browser : first graph with radio botton => second graph(get parameter and draw new graph)
I set my vias static variable here
<filter:code attributes=lang="ruby">
def view
self.setVias(params[:channel].to_i)
puts getVias #here it print well (not zero)
@graph2 = open_flash_chart_object(1000,700,"/test_it/graph_result")
@columnNum2 = self.getColumn(self.parseCSV)
end
< /filter:code>
And here I get it and the value of vias became ‘0′
<filter:code attributes=lang="html">
def graph_code
vias = self.getVias
puts vias #always change to 0
#some other code
end
< /filter:code>
I have same problem with totem which is about pass the parameter to graph_code
I’ve tried to use static variable and global variable but failed
And I don’t know why it fails. (the variance vias became ‘0′)
I do like this : test_it_controller => index.erb.html => test_it_controller => view.erb.html
In web browser : first graph with radio botton => second graph(get parameter and draw new graph)
I set my vias static variable here
<filter:code attributes=lang="ruby">
def view
self.setVias(params[:channel].to_i)
puts getVias #here it print well (not zero)
@graph2 = open_flash_chart_object(1000,700,"/test_it/graph_result")
@columnNum2 = self.getColumn(self.parseCSV)
end
</filter:code>
And here I get it and the value of vias became ‘0′
<filter:code attributes=lang="html">
def graph_code
vias = self.getVias
puts vias #always change to 0
#some other code
end
</filter:code>
@Wooram - you have graph_result and graph_code, are they supposed to be the same? Can you show me the graph_result method if it is different? You will want to pass your variables as get params like this:<filter:code attributes=lang="ruby">@graph2 = open_flash_chart_object(1000,700,"/test_it/graph_result?vias=#{getVias}")
</filter:code>And then retrieve it like this:<filter:code attributes=lang="ruby">def graph_result
vias = params[:vias]
…
end</filter:code>
Thanks Charlie. Actually this was a good opportunity to migrate to Rails2. So I won’t have to use 2 versions of OFC. Anyway I had prepared this migration long ago but never found an urgent reason to commit it !
hello:
I try the example of your tutorial but not run.
the controller is:
<filter:code attributes=lang="ruby">
class PruebaController < ApplicationController
def grafico1
# @graph = open_flash_chart_object(600,300,"/prueba/graph_code1")
@graph = open_flash_chart_object(600,300,"/prueba/test")
end
def test
render :text => %’{"title": {"text": "MY TITLE"}, "elements": [{"type": "bar_glass", "values": [1, 2, 3, 4, 5, 6, 7, 8, 9]}]}’
end
</filter>
the HTML code in ‘grafico1.rhtml’ is:
<filter:code attributes=lang="ruby">
<html>
<head>
<title>Grafico creado con Open flash chart</title>
</head>
<body>
<h1>Grafico generado con Open flash chart</h1>
<% javascript_include_tag "swfobject" %>
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
<%= @graph %>
</body>
</html>
</filter>
my error is:
Open Flash Chart IO Error
Loading test data
Error #2032
In the WEBrick server console:
127.0.0.1 - - [17/Sep/2008:00:08:42 Hora estƔndar romance] "GET /prueba/grafico1 HTTP/1.1" 200 1272
- -> /prueba/grafico1
127.0.0.1 - - [17/Sep/2008:00:08:42 Hora estƔndar romance] "GET /javascripts/swfobject.js HTTP/1.1" 304 0
http://127.0.0.1:3000/prueba/grafico1 -> /javascripts/swfobject.js
127.0.0.1 - - [17/Sep/2008:00:08:42 Hora estƔndar romance] "GET /data-files/x-axis-labels-3.txt HTTP/1.1" 404 644
http://127.0.0.1:3000/open-flash-chart.swf -> /data-files/x-axis-labels-3.txt
I dont know why appears ‘/data-files/x-axis-labels-3.txt’
hello: I try the example of your tutorial but not run. the controller is:
<filter:code attributes=lang="ruby">
class PruebaController < ApplicationController
def grafico1
@graph = open_flash_chart_object(600,300,"/prueba/test")
end
def test
render :text => %’{"title": {"text": "MY TITLE"}, "elements": [{"type": "bar_glass", "values": [1, 2, 3, 4, 5, 6, 7, 8, 9]}]}’
end
< /filter:code>
the HTML code in ‘grafico1.rhtml’ is:
<filter:code attributes=lang="html">
<html>
<head>
<title>Grafico creado con Open flash chart</title>
</head>
<body>
<h1>Grafico generado con Open flash chart</h1>
<% javascript_include_tag "swfobject" %>
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
<%= @graph %>
</body>
</html>
< /filter:code>
my error is: Open Flash Chart IO Error Loading test data Error #2032.
In the WEBrick server console:
127.0.0.1 - - [17/Sep/2008:00:08:42 Hora estĆ”ndar romance] "GET /prueba/grafico1 HTTP/1.1" 200 1272 - -> /prueba/grafico1 127.0.0.1 - - [17/Sep/2008:00:08:42 Hora estĆ”ndar romance] "GET /javascripts/swfobject.js HTTP/1.1" 304 0 http://127.0.0.1:3000/prueba/grafico1 -> /javascripts/swfobject.js 127.0.0.1 - - [17/Sep/2008:00:08:42 Hora estĆ”ndar romance] "GET /data-files/x-axis-labels-3.txt HTTP/1.1" 404 644 http://127.0.0.1:3000/open-flash-chart.swf -> /data-files/x-axis-labels-3.txt I dont know why appears ‘/data-files/x-axis-labels-3.txt’
hello: I try the example of your tutorial but not run. the controller is:
<filter:code attributes=lang="ruby">
class PruebaController < ApplicationController
def grafico1
@graph = open_flash_chart_object(600,300,"/prueba/test")
end
def test
render :text => %’{"title": {"text": "MY TITLE"}, "elements": [{"type": "bar_glass", "values": [1, 2, 3, 4, 5, 6, 7, 8, 9]}]}’
end
</filter:code>
the HTML code in ‘grafico1.rhtml’ is:
<filter:code attributes=lang="html">
<html>
<head>
<title>Grafico creado con Open flash chart</title>
</head>
<body>
<h1>Grafico generado con Open flash chart</h1>
<% javascript_include_tag "swfobject" %>
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
<%= @graph %>
</body>
</html>
</filter:code>
my error is: Open Flash Chart IO Error Loading test data Error #2032.
In the WEBrick server console:
127.0.0.1 - - [17/Sep/2008:00:08:42 Hora estĆ”ndar romance] "GET /prueba/grafico1 HTTP/1.1" 200 1272 - -> /prueba/grafico1 127.0.0.1 - - [17/Sep/2008:00:08:42 Hora estĆ”ndar romance] "GET /javascripts/swfobject.js HTTP/1.1" 304 0 http://127.0.0.1:3000/prueba/grafico1 -> /javascripts/swfobject.js 127.0.0.1 - - [17/Sep/2008:00:08:42 Hora estĆ”ndar romance] "GET /data-files/x-axis-labels-3.txt HTTP/1.1" 404 644 http://127.0.0.1:3000/open-flash-chart.swf -> /data-files/x-axis-labels-3.txt I dont know why appears ‘/data-files/x-axis-labels-3.txt’
@Javier - Can you post the HTML that is produced (the view source)?
What version of Rails?
hello:
the rails version is 1.2.6
the html code is:
<filter:code attributes=lang="html">
<html>
<head>
<title>Grafico creado con Open flash chart</title>
</head>
<body>
<h1>Grafico generado con Open flash chart</h1>
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
<div id="flashcontent"></div>
<script type="text/javascript">
var so = new SWFObject("/open-flash-chart.swf", "chart","600","300", "9", "#FFFFFF");
so.addVariable("data", "%2Fprueba%2Ftest");
so.addParam("allowScriptAccess", "sameDomain");
so.write("flashcontent");
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"
width="600" height="300" id="ie_chart" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="/open-flash-chart.swf?600&height=300&data=%2Fprueba%2Ftest" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<embed src="/open-flash-chart.swf?data=%2Fprueba%2Ftest" quality="high" bgcolor="#FFFFFF" width="600" height="300" name="chart" align="middle" allowScriptAccess="sameDomain"
type="application/x-shockwave-flash" pluginpage="http://ww.macromedia.com/go/getflashplayer" id="chart"/>
</object>
</noscript>
</body>
</html>
< /filter:code>
thanks.
@javier - the html did not come through very well, would you mind reposting it? And take out the space between < /filter:code>
I got error when I tried to install the plugin
C:\rubydev\test>ruby script/plugin install git://github.com/pullmonkey
/open_flash_chart.git –force
Plugin not found: ["git://github.com/pullmonkey/open_flash_chart.git"]
@Shawn - not sure why that is, but try this instead:
ruby script/plugin install http://github.com/pullmonkey
/open_flash_chart.git –force
* changed the git:// to http://
Great plugin, really did some nice stuff there!
Only problem is, I can’t seem to get it to work on a current project of mine.
I tried it on a new project just to test it, it worked perfectly. But on my already begun project, it won’t. I get the infamous #2032 error, just like Victor. The div containing the flash object doesn’t get created.
The thing I might see not working is the fact that I’m using restful routing? On the other hand, if it couldn’t find the graph_code action, it wouldn’t display anything at all.
I’m using the basic code you provided above. Nothing seems to do it… only worked on a brand new project.
Here’s what’s returned:
<filter:code attributes=lang="html">
<script src="/javascripts/swfobject.js" type="text/javascript">
</script>
<object id="flash_content_UStmgNb+" width="600" height="300" type="application/x-shockwave-flash" data="/open-flash-chart.swf" style="visibility: visible;">
<param name="flashvars" value="data-file=%2Fconsultations%2Fgraph_code"/>
</object>
<script type="text/javascript">
</script>
<noscript> <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="300" id="chart_UStmgNb+" align="middle"> <param name="allowScriptAccess" value="sameDomain" /> <param name="movie" value="/open-flash-chart.swf?data=%2Fconsultations%2Fgraph_code" /> <param name="quality" value="high" /> <param name="bgcolor" value="#FFFFFF" /> <embed src="/open-flash-chart.swf?data=%2Fconsultations%2Fgraph_code" quality="high" bgcolor="#FFFFFF" width="600" height="300" name="chart_UStmgNb+" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="chart_UStmgNb+" /> </object> </noscript>
< /filter:code>
Oops, don’t know what happened, let me try again… also, I was viewing the source with Firebug and it didn’t show me the containing div. When I did view source though, here’s what was returned.
<filter:code attributes=lang="html">
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
<div id="flash_content_RH3+rtB0"></div>
<script type="text/javascript">
swfobject.embedSWF("/open-flash-chart.swf", "flash_content_RH3+rtB0", "600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Fconsultations%2Fgraph_code"});
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="300" id="chart_RH3+rtB0" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="/open-flash-chart.swf?data=%2Fconsultations%2Fgraph_code" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<embed src="/open-flash-chart.swf?data=%2Fconsultations%2Fgraph_code" quality="high" bgcolor="#FFFFFF" width="600" height="300" name="chart_RH3+rtB0" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="chart_RH3+rtB0" />
</object>
</noscript>
</filter:code>
@Jerome - If it can’t find the graph_code action then it will still show the loading error. That is probably the number on cause. So browse to the consultations/graph_code action in your browser and let me know what you get. You should see some JSON on the screen.
Hi,
I seem to be having possibly similar problems. (Incidentally, I’ve noticed that any small error in the graph_code definition will result in the 2032 error.)
Here’s what I’ve got set up -
In my controller I have:
def generate_graph
@graph = open_flash_chart_object(600,300,"/metrics/graph_code")
render :partial => ‘generate_graph’, :layout => false
end
def graph_code
@metric = Metric.find(session[:metric_id])
title = Title.new("My Title")
..blah blah to set up the graph for this metric
render :text => chart.to_s
end
Then the partial _generate_graph.html.erb simply displays the graph as follows:
<%= @graph %>
This works for me EXCEPT it seems like it caches the graph_code definition such that if I make a change, the graph isn’t updated. In other words it "acts like" this part is cached:
def
@metric = Metric.find(session[:metric_id])
..blah blah to set up the graph
render :text => chart.to_s
end
So, if the session[:metric_id] value changes, the new data is displayed however if I attempt to modify the title, the old title remains even if I dump my cache, and/or close my browser and restart it.
I’ve also noticed that if I attempt to change the name of my action, I get the 2032 error.
Before:
def generate_graph
@graph = open_flash_chart_object(600,300,"/metrics/graph_code")
render :partial => ‘generate_graph’, :layout => false
end
def graph_code
…blah blah set up graph
render :text => chart.to_s
end
*** The above works ***
After change graph_code to graph_code2, (produces 2032 error):
def generate_graph
@graph = open_flash_chart_object(600,300,"/metrics/graph_code2")
render :partial => ‘generate_graph’, :layout => false
end
def graph_code2
…blah blah set up graph
render :text => chart.to_s
end
Using firebug I can see that the action graph_code is indeed changed to graph_code2, however it doesn’t seem to work.
So, it’s really acting like it’s caching the definition of the graph_code "action" and thus my chart doesn’t change other than the variable components. Is this expected behavior? If so, is there a way I can somehow refresh the definition of the graph_code action?
Note: I can post the before and after firebug data if you like.
Thanks,
Ed
@Ed - ok, so the changes probably don’t take effect because you aren’t restarting the application. Second, changing the code to say go to graph_code2 and then getting the 2032 error seems to point to the same problem. Have you tried going to the graph_code2 action yourself?
Yes, an error 2032, means ’something’ is wrong, the only way to see what exactly is wrong is to look in the logs. Or browse to the url that open-flash-chart.swf is accessing and go from there.
Charlie,
Thanks!
Is there a way for me to restart the application?
Thanks,
Ed
@Ed - How did you start it?
Are you running it locally?
Is it hosted somewhere?
If you are running it locally, try one of these:
1) if you used script/server, then just use ctrl-c to stop the server, the start it again.
2) if you used mongrel_rails start ….. (without a -d) then just ctrl-c and start it again.
3) if you used mongrel_rails start …. -d, the just type mongrel_rails restart.
4) if you are using apache with fcgi or fcgid, the restart apache.
5) if you are using something on windows … ?
If you are hosting it somewhere then they usually use fcgi, so you can just do:
killall dispatch.fcgi a few times and check that the processes were killed via ps aux | grep fcgi.
Hi Charlie,
Good news though, things are working fine now! Once again thanks and, NICE JOB!
We’re using apache and mongrel. (I was actually wondering if there was a way to reload it w/out restarting the browser.)
One final question: Do you know if a stacked bar graph is supported?
Cheers!
-ed
@Ed - all right, good news
Basically, whatever you see in the OFCII docs you should be able to do. So, it should be supported - <a href="http://teethgrinder.co.uk/open-flash-chart-2/stacked-bar-chart.php">http://teethgrinder.co.uk/open-flash-chart-2/stacked-bar-chart.php</a>.
Hi Charlie,
A little bump in the road. As previously I have things set up just as in your tutorial with an action that calls that does:
@graph = open_flash_chart_object(x,y,"path/graph_code")
In my graph code action I call a method to get my metrics:
def graph_code
@data_points = Measurement.graph_data(@metric.id,data_samples)
… set up the graph …
end
However, if I change the specification in my method, I get the dreaded 2032 error. Similarly if I change the name of the method from say graph_data to my_graph_data. I’ve tried bouncing the http and mongrel processes and restarting my browser, I’ve bounced apache and mongrel and tried from a different computer - no dice. Is there perhaps some file cache on the server that I’m unaware of? Any ideas? (Other than that things are working great! I really need to change my specification though. )
MTIA,
Ed
Good grief!
ugh… (sorry.)
Seems like I always figure things out AFTER I finally break down and ask for your assistance. Please disregard my former post. I’m good and yes, it was an idiotic mistake.
Thanks,
Ed
Hi!
I’ve downloaded your sample OFC2 project which is up and running via mongrel_rails cluster::start now. The browser is pointing to http://…/test-it but the screen stays blank. I don’t see whats wrong. Everything should be set up correctly. The source-code is:
<filter:code attributes=lang="html">
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
<div id="flash_content_MTIyNDUwMjY5OS4yNDA5OCUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl"></div>
<script type="text/javascript">
swfobject.embedSWF("/open-flash-chart.swf", "flash_content_MTIyNDUwMjY5OS4yNDA5OCUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl", "600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Ftest_it%2Fgraph_code"});
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="300" id="chart_MTIyNDUwMjY5OS4yNDA5OCUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="/open-flash-chart.swf?data=%2Ftest_it%2Fgraph_code" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<embed src="/open-flash-chart.swf?data=%2Ftest_it%2Fgraph_code" quality="high" bgcolor="#FFFFFF" width="600" height="300" name="chart_MTIyNDUwMjY5OS4yNDA5OCUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="chart_MTIyNDUwMjY5OS4yNDA5OCUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" />
</object>
</noscript>
< /filter:code>
Where is my problem?
@Meik - install the new plugin in the downloaded application. Just run this from the RAILS_ROOT.
script/plugin install git://github.com/pullmonkey/open_flash_chart.git –force
Are you using IE? There was a div naming length bug in IE that has since been fixed. I will update the sample application when I get a chance.
Hi Charlie,
The more I use this the slickerer it gets! Thanks! Now for my question(s)
1) Is there a way to add tooltip text to line graphs similar to bar graphs and version 1? I’m currently adding tooltips to bar graphs as follows:
xvals_ary[i][j] = BarValue.new(value)
xvals_ary[i][j].set_tooltip("blah" + "<br>#val#")
I’m not clear if method used in OFCI will work and I didn’t find a corresponding LineValue.new method in OFCII. Could you possibly point me in the right direction?
2) Is it possible to use the link_to_remote function to link back to the controller and generate a new graph? If so, could you possibly post or reply with a code snippet to get me started?
Thanks again!
-Ed
Hey charlie,
my problem is obsolete now. I need to have the flashplayer installed and working properly.
Sorry.
But another question: Is there a complete documentation about all charts usable in rails with the correct syntax?
Hello,
I’m having the same problem as Totem mentioned above. The one about getting "Invalid argument" in swfobject.js for IE6.
Has there been a resolution to this?
Same situation, IE6 fails, FF works fine, though I am using Rails 2.1.1
Thanks,
John Schank
Some follow up details…
1. The error seems to be happening on the line in swfobject.js that says: i.addRule(m,j)
2. The rule being added, j, is visibility:hidden
3. I suppose it might be possible that the enclosing div (around the graph) does not have an id, and the javascript code might be expecting one. But I’m no JS developer, so I can’t really tell.
Maybe this will help.
Thanks,
John Schank
Hi there,
It turns out that my problem is caused by using jQuery and swfObject together. On IE, there is a problem with detecting document ready.
I modified the code in open_flash_chart_object.rb to wrap the swfobject.embedSWF in a jQuery check for document ready.
I’d like to send it to you, but I don’t know where. I’ll post the "active ingredient here"
<script type="text/javascript">
$(document).ready(function(){
swfobject.embedSWF("#{base}open-flash-chart.swf", "#{div_name}", "#{width}", "#{height}", "9.0.0", "expressInstall.swf",{"data-file":"#{url}"});
});
</script>
I emphatically do not understand any ramifications of this change, other than it fixes my problem on IE. Please feel free to make an appropriate official change. (Perhaps detecting jQuery vs prototype or something) I pretty much totally flew by the seat of my pants and tried suggestions from other folks who actually know what they’re doing.
Key insight credit goes to this post: http://www.chapter31.com/2007/09/28/jquery-and-swfobject-conflict/
Thanks,
John Schank
@Ed - glad it is working for you.
1) Is there a way to add tooltip text to line graphs
similar to bar graphs and version 1?
Answer: whatever is available and documented here - http://teethgrinder.co.uk/open-flash-chart-2/ should work. I will dig around a bit for you, maybe do a post if I find something of value.
2) Is it possible to use the link_to_remote function to link back to the controller and generate a new graph? If so, could you possibly post or reply with a code snippet to get me started?
Answer: Yes, it is - I did an example and have a few javascript helpers for you to use if you want, all explained here - http://pullmonkey.com/2008/9/23/open-flash-chart-ii-javascript-part-3
@Meik -
Your Question: But another question: Is there a complete documentation about all charts usable in rails with the correct syntax?
Answer: Yes, I keep the ruby library inline with the php library and to simplify my life and yours. This way I can just point users to the existing (more thorough) documentation here - http://teethgrinder.co.uk/open-flash-chart-2/
He uses php, so where you see :
$line_dot = new line_dot();
Change to:
line_dot = LineDot.new
And where you see:
$line_dot->set_values( array(9,8,7,6,5,4,3,2,1) );
Change to:
line_dot.set_values( [9,8,7,6,5,4,3,2,1] )
Hope that makes sense
@John Schank - Thanks for commenting on your fix, I am sure it will help others. That is probably the best we will be able to do. I am not sure this warrants an "official" change, since it only affects IE when used with jquery. Maybe I am wrong - what do you think? Also, were you using the latest build as of yesterday?
I wonder if the jquery noConflict() method would help in this situation. That would require that you run with both prototype and jquery, which may not be acceptable for some users.
I will give it some more thought and thanks again for the update.
@Charlie.
I’ll try the latest and also the noConflict() though I’m not sure how to use the noConflict method.
For both prototype and jquery, I had OTHER problems with IE when I was using both. It wasn’t until I deleted prototype, which required me to delete active_scaffold - which it turns out I wasn’t really using. Though it is certainly possible that noConflict() would have solved THAT problem, and perhaps also this problem.
Since I branched my code before trying anything, (git rocks) I’ll try the latest and noConflict on my master branch and see what happens.
Thanks again,
John Schank
Final follow up…
Ok, apparently I am an idiot. It looks like the latest OFC from github, combined with noConflict() and slight tweaks to my javascript code to use jQuery or prototype as appropriate, works fine and dandy on IE as well as Safari.
My guess is that simply using noConflict() would have spared me much anguish.
Funny how i can get so frustrated at a problem, and angry, then find out the problem was me.
Thanks for your patience.
John
P.S. the change I made does work. It is just completely unnecessary.
Hi Charlie,
What I’d really like to do is attach a link to the data such as in this pie chart in OFC I:
http://pullmonkey.com/projects/open_flash_chart/view_source_code/pie_links
In the example you create an array of links and then add them to the pie values as follows:
g.pie_values(data, %w(IE FireFox Opera Wii Other), links)
The links appear to simply be javascript calls:
"javascript:alert(’temp’)"
Unfortunately, of java I know nil.
1) Will these links work in OFC II? If so, will they work with bar graphs in addition to pie charts?
2) Could you possibly post a javascript call that will call a controller and action with some parameters?
Thank!
-Ed
@Ed -
1) That example with pie_values is for OFC1, which I think you know based on what you write in question 1, but for everyone else’s benefit. Anyway, all <a href="http://teethgrinder.co.uk/open-flash-chart-2/">the documentation and examples for OFC2</a> map straight into the rails implementation. This means if you find an example that you like over there, you will be able to do it in rails with very little work. For example, see <a href="http://harryseldon.thinkosphere.com/2008/10/22/scatter-line-chart-example-with-ofc2#comment-50">Harry Seldon’s latest example</a>. He leaves the php in the example code, so you can see the translation.
So for example in php that does the pie value links/urls — <a href="http://teethgrinder.co.uk/open-flash-chart-2/adv-pie-chart-3.php">Check out this example</a>.
2) What do you mean? Instead of just using a link?
Is this in reference to the pie charts? See if the answer to #1 helps, if not, just let me know what you are attempting to do, there are quite a few ways and I don’t want to send you down the wrong path.
I get:
uninitialized constant TestItController::Title
when I try this. Title.new is the problem. I’m not used to creating new objects for anything but models, so I don’t know what to debug here. What could be the problem?
@Matthew - is this the latest code? or an older version.
Well depending - if it is the older code, I.e., a week ago, then you will want to make sure the plugin is loaded and that you restarted your app.
If it is the latest release, make sure to include OpenFlashChart
@charlie - yeah, i had forgotten to include it in the application controller. Now I’m getting this:
undefined method `new’ for OpenFlashChart:Module
looking at http://localhost:3000/test_it/graph_code
Matthew, I would bet you are using OpenFlashChart.new instead of the new "OpenFlashChart::Base.new" syntax.
(Charlie will maybe add the backward compatibility to keep the first syntax).
Yep, you were right… and now I’m getting this one:
ArgumentError (wrong number of arguments (1 for 0)):
C:/Development/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/json/encoding.rb:21:in `to_json’
I do not know that error. But the error is not coming from active-support. So as a generale rule for OFC and Rails app debugging you need to look at the last line referring to a line in your OWN code. Have a look at your log to see the full error stack.
It seems like a compatibility issue between my version of rails and open_flash_chart. Here’s the full error:
ArgumentError (wrong number of arguments (1 for 0)):
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/json/encoding.rb:21:in `to_json’
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/json/encoding.rb:21:in `send’
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/json/encoding.rb:21:in `encode’
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/json/encoding.rb:31:in `raise_on_circular_reference’
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/json/encoding.rb:20:in `encode’
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/json/encoders/hash.rb:42:in `to_json’
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/json/encoders/hash.rb:41:in `map’
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/json/encoders/hash.rb:41:in `to_json’
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/core_ext/object/misc.rb:28:in `returning’
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/json/encoders/hash.rb:40:in `to_json’
/vendor/plugins/open_flash_chart/lib/open_flash_chart/base.rb:34:in `to_json’
/vendor/plugins/open_flash_chart/lib/open_flash_chart/base.rb:25:in `to_s’
/app/controllers/test_controller.rb:14:in `graph_code’
Not sure why it wants arguments…
@Matthew - try the latest. We have been going back and forth with the json stuff. There is a json gem out there that is causing problems for people.
Also .. no need to include the OpenFlashChart module anymore, and you can use OpenFlashChart.new instead of OpenFlashChart::Base.new
Basically, stick this example in and it should still work.
So let me know how that goes for you.
Just reinstalled it from the git:
git://github.com/pullmonkey/open_flash_chart.git
Unless there is a different repo I should be using. It only works for me if I do OpenFlashChart::Base.new
@Matthew - did you restart your server?
Can you verify your README under RAILS_ROOT/vendor/plugins/open_flash_chart/README?
It should contain code that shows usage like this:
OpenFlashChart.new …
if it still says:
OpenFlashChart::Base.new
then you have an old version from github.
Let me know.
Hey I found a solution for the
‘Open Flash Chart
IO ERROR
Loading test data
Error #2032′
This bug is occured when my version of
open-flash-chart.swf is 2.0
The 1.97 version work like a charm for me.
Hope that can help you
@BLA - that means that your code is setup for use with OpenFlashChart I (prior to the JSON version of OFC)
Are you using the old svn version of OFCI?
I am having difficulty installing the plugin. I’ve tried both installation methods suggested here.
—
script/plugin install git://github.com/pullmonkey/open_flash_chart.git
removing: /path/to/app/vendor/plugins/open_flash_chart/.git
Initialized empty Git repository in /path/to/app/vendor/plugins/open_flash_chart/.git/
fatal: The remote end hung up unexpectedly
fetch-pack from ‘git://github.com/pullmonkey/open_flash_chart.git’ failed.
—
script/plugin install http://github.com/pullmonkey/open_flash_chart.git –force
removing: /path/to/app/vendor/plugins/open_flash_chart/.git
Initialized empty Git repository in /path/to/app/vendor/plugins/open_flash_chart/.git/
shallow over http or ftp not supported
—
I’ll just download it from github and install manually, but I was curious to know why this might be happening.
Thanks.
@Eric - all I know right now is that github is having problems with the queue and some lag - http://github.wordpress.com/
Hopefully, it will clear up soon.
I just downloaded the latest version from github and when I try to display a chart I just get a blank area. I’ve tracked the problem down to some changes in lib/open_flash_chart/base.rb. If I change the lines that say ‘to_json2′ back to ‘to_json’ it works. With the calls to ‘to_json2′ I get extra slashes in my output.
Am I missing something that makes the ‘to_json2′ fix necessary?
any way to change the background color?
@Jeremy - are you using a json gem?
@Matthew - Yes, http://teethgrinder.co.uk/open-flash-chart-2/background.php as an example in php. The conversion from anything done is php is pretty straight forward. In this case it would be from:<filter:code attributes=lang="ruby">#example in php
$chart->set_bg_colour( ‘#FFFFFF’ );
</filter:code>to<filter:code attributes=lang="ruby">#example of first way in ruby using the plugin
@chart.set_bg_colour( ‘#FFFFFF’ )
</filter:code>or<filter:code attributes=lang="ruby">#example of second way in ruby
@chart.bg_colour = ‘#FFFFFF’
</filter:code>
I’m having a similar, but not the same, issue as Jeremy Green. I’m seeing the "loading data" notice and then a blank screen. The sample OFC2 rails app does work though. I did a careful comparison and the only difference I can find is in the formatting of the JSON generated. Specifically the sample app looks like this:
{"title": {"text": "MY TITLE"}, "elements": [{"type": "bar_glass", "values": [1, 2, 3, 4, 5, 6, 7, 8, 9]}]}
whereas my app looks like this:
{"title":"{\"text\":\"MY TITLE\"}","elements":["{\"type\":\"bar_glass\",\"values\":[1,2,3,4,5,6,7,8,9]}"]}
As you can see the title and elements objects are given an extra surrounding quotes and then the inside quotes are escaped. I wasn’t able to figure out where this was coming from. Unfortunately for me switching the call from to_json2 to to_json doesn’t fix the problem for me. And I do have the json gem installed, v1.1.3.
I probably should have mentioned: rails 2.1.1, ruby 1.8.6
@jeffb - ok, I guess I will have to install the json gem and get to the bottom of this. So the way I have it now works without the json gem but breaks with the json gem and the way we *had* it works with the json gem but breaks without the json gem.
Hi there,
I use Rails 2.1.1, and I was experiencing the same issue as Totem had indicated back in August.
When viewing on your site, I could see the charts in IE 7. But, while I could see the charts using FF, served from my local machine, I could not see them with the IE 7 browser.
I turned on javascript debug, and saw that an invalid argument was being passed. After commenting out the line (shown below), IE 7 shows the chart just fine.
This has probably been solved by others, but I did not see the resolution to Totem’s issue, so figured I’d post this, in the hopes someone could let me know if there is a better way to fix the issue, or provide a hint to others.
Take care,
Mike
Hi there,
I use Rails 2.1.1, and I was experiencing the same issue as Totem had indicated back in August.
When viewing on your site, I could see the charts in IE 7. But, while I could see the charts using FF, served from my local machine, I could not see them with the IE 7 browser.
I turned on javascript debug, and saw that an invalid argument was being passed. After commenting out the line (shown below), IE 7 shows the chart just fine.
This has probably been solved by others, but I did not see the resolution to Totem’s issue, so figured I’d post this, in the hopes someone could let me know if there is a better way to fix the issue, or provide a hint to others.
function A(m, j){
if (a.ie && a.mac) {
return
}
var l = g.getElementsByTagName("head")[0], k = Y("style");
k.setAttribute("type", "text/css");
k.setAttribute("media", "screen");
if (!(a.ie && a.win) && typeof g.createTextNode != Z) {
k.appendChild(g.createTextNode(m + " {" + j + "}"))
}
l.appendChild(k);
if (a.ie && a.win && typeof g.styleSheets != Z && g.styleSheets.length > 0) {
var i = g.styleSheets[g.styleSheets.length - 1];
if (typeof i.addRule == P) {
//commented out this line, and it works
// i.addRule(m, j)
}
}
}
Take care,
Mike
Hi, great work! thanks!
I wonder if the "set_on_click" function to call
an action is implemented in the class BarFilled.
It works perfectly in the Lines classes but not
on the Bar.
thanks
r.
Hello I have problem with using OFC2
The problem is my controller is connected with model
so the controller name is Images_controller which is connected with model named Image
I want to use OFC in the images controller
The problem looks like /images/graph_code is used as
select from image where id = graph_code
so the error message is:
ActiveRecord::RecordNotFound in ImagesController#show
Couldn’t find Image with ID=ph_graph
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:1528:in `find_one’
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:1511:in `find_from_ids’
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:590:in `find’
app/controllers/images_controller.rb:18:in `show’
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:1253:in `send’
/Library/Ruby/Gems/1.8/gems/actionpack-
…
need help ^^
@Rosario - Looking through the AS code and through the php code, it (on-click events for bar charts) doesn’t seem to be supported yet.
I did however find a OFC forum thread asking about it, <a href="http://forums.openflashchart.com/viewtopic.php?f=5&t=305&p=1696&hilit=set_on_click#p1696">here</a>.
But the suggestion to use BarValue with top and on-click did not work for me. Even building a simple hardcoded set of JSON didn’t work with the suggestion.
Before the plugin can support it, the swf needs to support it
Let me know if you (or anyone) find anything.
@wooram - you are having a problem with restful routes
Using `rake routes` you can learn a lot about how requests are handled given the url and either GET, DELETE, POST or PUT. Run `rake routes` and look for GET for the basic images path.
It is being handled by the show action and the first argument is id. So you need to make a :collection member for your restful route/resource.
A good resource for this is <a href="http://api.rubyonrails.org/classes/ActionController/Resources.html">here</a>.
Right now, in your config/routes.rb you probably have a line like this:<filter:code attributes=lang="ruby">map.resources :images</filter:code>You need to extend this from its defaults and add the graph_code action with something like this:<filter:code attributes=lang="ruby">map.resources :images, :collection => { :graph_code => :get }</filter:code>Then save and restart your server - try again
Charlie,
Two things:
1. I’ve run into the same problem that jeffb had a few months ago. The JSON rendered from the to_s method is invalid. Have you found a solution to this issue?
I’m at a loss here, because it works in one project, but not in another.
This project is running Rails 2.0.2 on Ruby 1.8.6 with the JSON 1.1.3 gem installed.
http://pullmonkey.com/2008/7/23/open-flash-chart-ii-plugin-for-ruby-on-rails-ofc2#comment-50921
2. You can get the re-compiled open-flash-chart.swf file with support for bar on-click events here:
- http://forums.openflashchart.com/viewtopic.php?f=5&t=305&p=1922#p1922
I modified your plugin, Charlie by adding an on_click method to the BarBase class like so:
<pre>
class BarBase < Base
def on_click(event)
@on_click = event
end
end
</pre>
@Eric -
1) Not sure on the JSON error, haven’t ever run into it. I will have to install the gem and see what happens for me then fix it
2) Thanks for pointing me to the updated swf, that will be helpful. But as for adding the on_click() method - it is unnecessary. I am using method_missing - see this <a href="http://github.com/pullmonkey/open_flash_chart/tree/master/lib/open_flash_chart/base.rb">file</a> at the very bottom. And since it inherits from Base, BarBase already has that method just like any other method it could ever want that only takes one argument. This allows for both bar.on_click = event and bar.set_on_click(event).
But just in case, take your method out and see that it works, and let me know.
I will package the new swf with the plugin.
Thank you.
@Eric -
I used your swf file and with great success, see <a href="http://pullmonkey.com/2009/1/8/open-flash-chart-ii-bar-graphs-with-on-click">this post</a>.
Hi
I’ve used the ofc2 plugin on windows XP and it works like a charm…
But now …I have deployed the same rails application on ubuntu 7.10…and I cant see my flash graphs on screen..Firebug gives error as:
"swfobject is not defined"
On checking the source of the page..I can see the javascript and the <div> too….
I have the javascript include tag in place….
Can anyone help me with this????
Thanks in advance…
@Zeba - a lot of your message got stripped out, repost using <a href="http://pullmonkey.com/2008/7/23/open-flash-chart-ii-plugin-for-ruby-on-rails-ofc2#comment-46303">code syntax highlighting</a>.
Also, do any of the pullmonkey graphs work for you. Just want to make sure you have a flash client installed.
Also, from firebug check "Net" and make sure there are no missing or erroneous files (no files that show up in red).
Hello…
I cannot get the background to change color. Neither of the following seems to work for me:
<filter:code attributes=lang="ruby">
chart.bg_color = ‘#ffffff’
< /filter:code>
<filter:code attributes=lang="ruby">
chart.set_bg_color(’#ffffff’)
< /filter:code>
I’m trying to put this in my controller, as such:
<filter:code attributes=lang="ruby">
chart = OpenFlashChart.new("My Title") do |c|
c << BarGlass.new(:values => tmp)
c.y_axis = y
c.x_axis = x
end
chart.bg_color = ‘#FFFFFF’
render :text => chart, :layout => false
< /filter:code>
What am I doing wrong?
@Ev - Very close - it is set_bg_colour or bg_colour=, so colour (british) instead of color.
@charlie - Oi! Always something right under my nose! Thanks!
Okay, back again with another issue!
I’m trying to add legends to my chart and I keep getting back a blank canvas. When I use
<filter:code attributes=lang="ruby">
y_legend = YLegend.new("test y")
…
chart.set_y_legend(y_legend)
</filter:code>
I get back a blank canvas (same with X Legend). If I further specify
<filter:code attributes=lang="ruby">
y_legend.set_style(’{font-size: 1em; color: red;}’)
</filter:code>
I get my chart back (it displays), but there is still no legend.
Any clue what might be wrong?
Hi..
In my earlier post, I mentioned that ofc2 was not working on my ubuntu m/c…
I get a javascript error as=>
swfobject is not defined…
I do have a flash client installed…as I can see other flash files…
Then I tried to paste the entire swfonject.js code in my view into the ’script’ tag…
this removed the "swfobject is not defined" error…but yet the graphs were not loaded on screen…
So now I have shifted back to ofc (1.9.7 version)and it works absolutely fine…
But please can you help me with the ofc2 graphs…
Thanks.
@Ev
Try this…
<filter:code attributes=lang="ruby">
g.set_x_legend("Disciplines", 12, "#736AFF")
g.set_y_legend("Medals", 12, "#736AFF")
< /filter:code>
@Ev - try using px instead. The swf object doesn’t seem to like ‘em’.
@Zeba - could you post your code? you may have already done so, but it looks like it got stripped out. I saw that you used the filter tags, but forget to remove the space between < and /filter:code>.
@Zeba - Thanks for the feedback, but that doesn’t seem to work either. I get the loading message when it’s loading my data, but when that’s done I still get a blank canvas. If I comment out the legends, it works fine. What gives?
@charlie - Setting the size to ‘px’ has the same effect; blank canvas. Any other thoughts?
@Ev - would you mind posting JSON for me to look at? Then I will be able to reproduce it.
Thanks.
@charlie - Here it is:
<filter:code attributes=lang="json">
{"y_axis": {"steps": 20, "max": 190, "stroke": 0, "min": 0, "grid-colour": "#efefef"}, "x_legend": "Test", "title": {"text": "Phone Log for Monday, Jan. 12 2009"}, "elements": [{"type": "bar_glass", "colour": "#FF007F", "values": [1, 6, 32, 2, 47, 21, 170, 53, 115, 34, 115, 6, 1, 115, 1, 12, 80, 150, 89, 3, 62]}], "x_axis": {"colour": "#333333", "grid-colour": "#ffffff", "labels": {"rotate": "vertical", "labels": [{"size": 12, "text": "Stacy", "colour": "#000000", "rotate": "diagonal"}, {"size": 12, "text": "Evan", "colour": "#000000", "rotate": "diagonal"}, {"size": 12, "text": "Kevin", "colour": "#000000", "rotate": "diagonal"}, {"size": 12, "text": "RyanR", "colour": "#000000", "rotate": "diagonal"}, {"size": 12, "text": "EYoung", "colour": "#000000", "rotate": "diagonal"}, {"size": 12, "text": "Kristin", "colour": "#000000", "rotate": "diagonal"}, {"size": 12, "text": "Nathan", "colour": "#000000", "rotate": "diagonal"}, {"size": 12, "text": "ShantaWashing", "colour": "#000000", "rotate": "diagonal"}, {"size": 12, "text": "Greg", "colour": "#000000", "rotate": "diagonal"}, {"size": 12, "text": "Ralph", "colour": "#000000", "rotate": "diagonal"}, {"size": 12, "text": "Elizabeth", "colour": "#000000", "rotate": "diagonal"}, {"size": 12, "text": "Larry", "colour": "#000000", "rotate": "diagonal"}, {"size": 12, "text": "Alyssakn", "colour": "#000000", "rotate": "diagonal"}, {"size": 12, "text": "Rodson", "colour": "#000000", "rotate": "diagonal"}, {"size": 12, "text": "Sales", "colour": "#000000", "rotate": "diagonal"}, {"size": 12, "text": "Alyssa", "colour": "#000000", "rotate": "diagonal"}, {"size": 12, "text": "Shanta", "colour": "#000000", "rotate": "diagonal"}, {"size": 12, "text": "Kai", "colour": "#000000", "rotate": "diagonal"}, {"size": 12, "text": "Ryan", "colour": "#000000", "rotate": "diagonal"}, {"size": 12, "text": "Buffy", "colour": "#000000", "rotate": "diagonal"}, {"size": 12, "text": "Sonata", "colour": "#000000", "rotate": "diagonal"}]}}, "bg_colour": "#ffffff"}
</filter:code>
Thanks for the help!
@Ev - Adding this to the JSON you provided works for me:<filter:code attributes=lang="ruby">…
"x_legend": { "text": "text for x", "style": "{font-size: 20px; color: #778877}" },
"y_legend": { "text": "text for y", "style": "{font-size: 20px; color: #778877}" },
…</filter:code>
Make sure to style both the x and y legend.
@charlie - Well, adding that didn’t work, but I went back and copy-pasted from one of your examples and now it seems to work. Perhaps I just copied it wrong when I tried it the first time. Thanks for the help and your patience!
A last question: I have my x-axis labels set to be diagonal, but the first letter of the longest label seems to be cut off at the bottom of the canvas. Is there anyway to fix this? Like to add some padding to the bottom of the canvas so that the longest label clears properly?
Hi,
I also ran into the json bug. If you have ruby json required anywhere in your code, you will see json with extra quotes. I have written more about it here
http://www.prateekdayal.net/tech/2009/02/10/open-flash-chart-ii-plugin-and-json-gem/
Also I found that line_base.rb has the values hardcoded and so it shows the same graph no matter what values you pass to it. Fix is to just delete the @values= line in line_base.rb
In the end, thanks for the awesome plugin
@Prateek - Sorry - still need to find some time to figure out the JSON gem problem.
But with regards to the hard coded values - I have to kindly disagree
Unless, I am missing something. The @values = line in the LineBase initialize() method is just the default and only set during initialize and will soon be overwritten. You will want to set the values yourself with something like line.values = <your own array goes here>
For example - see <a href="http://pullmonkey.com/2008/8/1/open-flash-chart-ii-line-graph">this post</a>.
Note the lines that have line_dot.values = data1 and line_hollow.values = data2. Both line_dot and line_hollow are inherited from LineBase, yet they work just fine.
However, if I am wrong (it happens) - would you mind providing me an example that breaks?
Thanks.
Hi,
I have no idea how to get ahold of you any other way, but for those who are still using v1 of this plugin, is there a way to disable animation of pie charts on page load, and if so, how? there is no documentation on this anywhere for v1, and the v2 method will not work.
@m - all the documentation for pie charts is here for version 1 - <a href="http://teethgrinder.co.uk/open-flash-chart/gallery-pie.php">http://teethgrinder.co.uk/open-flash-chart/gallery-pie.php</a>
From the looks of it, the answer is no - there is no way to disable pie chart animation. Keep looking though.
Remember that the rails plugin is just an interface to the existing OFC flash object. So the rails plugin can only do what the flash object allows.
I was trying to get two y-axis with version 2 of the plugin.
I managed to get a right y-axis, which behaves a bit different when it comes to range and labels, but ok.
But how do I attach a Line to the right axis?
And more about this … is there a documentation for the available functions?
Just looking at the ofc2-webpage doesn’t help me figure out the way this needs to be used in rails.
Thanks,
Juergen
i am getting the following error:
Open Flash Chart
IO ERROR
Loading test data
Error #2032
source of my index.rb looks like this..
<filter:code attributes=lang="html">
<script src="/javascripts/swfobject.js?1235983244" type="text/javascript"></script>
<div id="flash-content">
<div id="flash_content_hkNrPwTH"></div>
<script type="text/javascript">
swfobject.embedSWF("/open-flash-chart.swf", "flash_content_hkNrPwTH", "600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Fdeals%2Fgraph_code"}, {"wmode":"transparent"});
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="300" id="chart_hkNrPwTH" align="middle" wmode="transparent">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="/open-flash-chart.swf?data=%2Fdeals%2Fgraph_code" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<embed src="/open-flash-chart.swf?data=%2Fdeals%2Fgraph_code" quality="high" bgcolor="#FFFFFF" width="600" height="300" name="chart_hkNrPwTH" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="chart_hkNrPwTH" />
</object>
</noscript>
</div>
< /filter:code>
@meebo - Error 2032 is a very generic error, and it usually means that your rails code has an error in it. So check your rails logs and you will probably find your error.
recently, i just download the ofc v2 hyperion from sourceforge.net. seem that, I’m not alone facing the same problem..
Open Flash Chart
IO ERROR
Loading test data
Error #2032
my open-flash-chart.swf is in the root directory..
and the size is 257kb
<filter:code attributes=lang="php">
<? //test.php
include_once ‘ofc-library/open-flash-chart-object.php’;
open_flash_chart_object( 500, 250, ‘http://localhost/chart-data.php’,false);
?>
//chart-data.php
<?php
echo ‘now i at chart-data.php’;
// generate some random data:
srand((double)microtime()*1000000);
echo ‘hello000000′;
$max = 50;
$data = array();
for( $i=0; $i<12; $i++ )
{
$data[] = rand(0,$max);
}
// use the chart class to build the chart:
include_once( ‘ofc-library/open-flash-chart.php’ );
$g = new graph();
// Spoon sales, March 2007
$g->title( ‘Spoon sales ‘. date("Y"), ‘{font-size: 26px;}’ );
$g->set_data( $data );
// label each point with its value
$g->set_x_labels( array(’Jan’,'Feb’,'Mar’,'Apr’,'May’,'Jun’,'Jul’,'Aug’,'Sep’,'Oct’,'Nov’,'Dec’ ) );
// set the Y max
$g->set_y_max( 60 );
// label every 20 (0,20,40,60)
$g->y_label_steps( 6 );
// display the data
echo $g->render();
?>
Hello I met problem when I change the server system.
Before I use macbook with OS X 10.5
But When I change the rails project to Redhat machine(enterprise)
http://high.icu.ac.kr:3000/heat_datas/5
this problem happen..
I can’t see the flash part..
and same in another graph
http://high.icu.ac.kr:3000/ph_photos/call_graph
here I can’t see the graph(which use ajax - form remote tag and partial)
Instead of graph I can see the code in web browser
Above problems happen when I setup my new redhat machine and move my rails project to that machine
Do you have any idea?
Thankyou~
I use Chrome but i always get a Blank Page
Later I try it on IE with same results
I know it works on Firefox but I need on IE and Chrome
I really try so hard but nothing
I look for error on FF and get this warnings
Warning: Expected ‘,’ or ‘{’ but found ‘=’. Ruleset ignored due to bad selector.
Source File: http://172.28.20.60:3000/test_it
Line: 1
Could you help me please
@Jose - do my charts (the ones on this site) show up for you in IE and Chrome? If not then you may need to update/install a flash player for your browser.
@Charlie - in your website always get the charts no matter the browser
@Jose - well, that is good news
Can you browse to the JSON generating action and post the output?
Does anybody know if Open Flash Chart works with Ruby on Rails 1.2.3?
I’ve spent a fair amount of time trying to get this to work with no luck. OFC2 didn’t seem to work at all (didn’t embed any kind of flash object into the page).
OFC does embed a flash object onto the page but its blank. When I right click on the blank flash object, the context menu says ‘Movie not loaded…’
I’m running:
Ruby 1.8.5
RoR 1.2.3
CentOS 4.4
The rendered output is the same (blank flash object) in:
IE 6
FF 3.0.7
Does anybody know if Open Flash Chart works with Ruby on Rails 1.2.3?
I have spent a fair amount of time trying to get this to work with no luck.
OFC2 doesn’t seem to work at all as it wont even embed a flash object into the page. OFC however, DOES embed a flash object into the page, but its blank and when right clicking it, the context menu says ‘Movie not loaded…’
I am running:
Ruby 1.8.5
RoR 1.2.3
CentOS 4.4
The result is the same in both IE 6 and FF 3.0.7
Any help would be really appreciated.
Apologies for the double post! My first one randomly disappeared briefly.
I try direct access to /test_it/graph_code and get this respond
{"title": {"text": "MY TITLE"}, "elements": [{"type": "bar_glass", "values": [1, 2, 3, 4, 5, 6, 7, 8, 9]}]}
Do you see something wrong??
@Jose - that looks right to me. Can you post the generated HTML that has the embedded flash object in it, we should double check the paths in that.
Charlie Here it is
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
<div id="flash_content_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl"></div>
<script type="text/javascript">
swfobject.embedSWF("/open-flash-chart.swf", "flash_content_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl", "600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Ftest_it%2Fgraph_code"});
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="300" id="chart_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="/open-flash-chart.swf?data=%2Ftest_it%2Fgraph_code" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<embed src="/open-flash-chart.swf?data=%2Ftest_it%2Fgraph_code" quality="high" bgcolor="#FFFFFF" width="600" height="300" name="chart_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="chart_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" />
</object>
</noscript>
The comment doenst show everything
How do i put code on it??
@Jose - use this info:
<filter:code attributes=lang="ruby">
# change the attributes lang from ruby to html or whatever you want.
# Put your stuff here
# and for the line below, get rid of the space
< /filter:code>
<filter:code>
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
<div id="flash_content_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl"></div>
<script type="text/javascript">
swfobject.embedSWF("/open-flash-chart.swf", "flash_content_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl", "600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Ftest_it%2Fgraph_code"});
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="300" id="chart_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="/open-flash-chart.swf?data=%2Ftest_it%2Fgraph_code" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<embed src="/open-flash-chart.swf?data=%2Ftest_it%2Fgraph_code" quality="high" bgcolor="#FFFFFF" width="600" height="300" name="chart_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="chart_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" />
</object>
</noscript>
< /filter:code>
<filter:html>
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
<div id="flash_content_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl"></div>
<script type="text/javascript">
swfobject.embedSWF("/open-flash-chart.swf", "flash_content_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl", "600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Ftest_it%2Fgraph_code"});
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="300" id="chart_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="/open-flash-chart.swf?data=%2Ftest_it%2Fgraph_code" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<embed src="/open-flash-chart.swf?data=%2Ftest_it%2Fgraph_code" quality="high" bgcolor="#FFFFFF" width="600" height="300" name="chart_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="chart_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" />
</object>
</noscript>
</filter:html>
<code>
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
<div id="flash_content_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl"></div>
<script type="text/javascript">
swfobject.embedSWF("/open-flash-chart.swf", "flash_content_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl", "600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Ftest_it%2Fgraph_code"});
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="300" id="chart_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="/open-flash-chart.swf?data=%2Ftest_it%2Fgraph_code" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<embed src="/open-flash-chart.swf?data=%2Ftest_it%2Fgraph_code" quality="high" bgcolor="#FFFFFF" width="600" height="300" name="chart_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="chart_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" />
</object>
</noscript>
</code>
<filter:code attributes=lang="html">
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
<div id="flash_content_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl"></div>
<script type="text/javascript">
swfobject.embedSWF("/open-flash-chart.swf", "flash_content_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl", "600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Ftest_it%2Fgraph_code"});
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="300" id="chart_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="/open-flash-chart.swf?data=%2Ftest_it%2Fgraph_code" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<embed src="/open-flash-chart.swf?data=%2Ftest_it%2Fgraph_code" quality="high" bgcolor="#FFFFFF" width="600" height="300" name="chart_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="chart_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" />
</object>
</noscript>
< /filter:code>
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
<div id="flash_content_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl"></div>
<script type="text/javascript">
swfobject.embedSWF("/open-flash-chart.swf", "flash_content_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl", "600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Ftest_it%2Fgraph_code"});
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="300" id="chart_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="/open-flash-chart.swf?data=%2Ftest_it%2Fgraph_code" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<embed src="/open-flash-chart.swf?data=%2Ftest_it%2Fgraph_code" quality="high" bgcolor="#FFFFFF" width="600" height="300" name="chart_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="chart_MTIzODUxNTI3MS4yNSUyRnRlc3RfaXQlMkZncmFwaF9jb2Rl" />
</object>
</noscript>
Charlie please check the html above
@Jose - that looks fine. Any errors in the error logs? Is open-flash-chart.swf located in RAILS_ROOT/public? Is swfobject.js located in RAILS_ROOT/public/javascripts?
Firefox works but I got this error on the console
Warning: Expected ‘,’ or ‘{’ but found ‘=’. Ruleset ignored due to bad selector.
Source File: http://172.28.20.60:3000/test_it
Line: 1
Chrome doesn’t work
And this
Chrome JavaScript Debugger
Type ‘help’ for a list of commands.
attached to http://172.28.20.60:3000/test_it
uncaught exception TypeError: Cannot call method ‘appendChild’ of undefined
This is the Log
Processing TestItController#index (for 172.28.4.234 at 2009-04-01 00:54:51) [GET]
[4;36;1mSQL (16.0ms)[0m [0;1mSET client_min_messages TO 'panic'[0m
[4;35;1mSQL (16.0ms)[0m [0mSET client_min_messages TO 'notice'[0m
Rendering test_it/index
Completed in 2094ms (View: 1031, DB: 32) | 200 OK [http://172.28.20.60/test_it]
Processing TestItController#index (for 172.28.4.234 at 2009-04-01 00:58:11) [GET]
[4;36;1mSQL (15.0ms)[0m [0;1mSET client_min_messages TO 'panic'[0m
[4;35;1mSQL (0.0ms)[0m [0mSET client_min_messages TO 'notice'[0m
Rendering test_it/index
Completed in 31ms (View: 31, DB: 15) | 200 OK [http://172.28.20.60/test_it]
Processing TestItController#graph_code (for 172.28.4.234 at 2009-04-01 00:58:19) [GET]
[4;36;1mSQL (16.0ms)[0m [0;1mSET client_min_messages TO 'panic'[0m
[4;35;1mSQL (0.0ms)[0m [0mSET client_min_messages TO 'notice'[0m
Completed in 234ms (View: 0, DB: 16) | 200 OK [http://172.28.20.60/test_it/graph_code]
Hi
I have a graph with y-axis and y-right-axis.My problem is at different points the two lines of the graph coincide..So when pointing on the tooltip I get only the y value of one of the line How can i solve this I have seen in some other graph when we double click on either of line only that line seen and other disappers so that to read its axis values properly
Sk
@Chalie
Did you find something in my logs or javascript debuggers?
@Jose - nothing that I see. What other javascript files are you loading and what other javascript is being executed?
@sk - This would have to be solved at the swf level. See <a href="http://forums.openflashchart.com/">these forums (OFC Forums)</a>. However, if you send me a link to one of the working examples you mention, I might be able to come up with a solution.
@charlie - I just running the example code
I have the chart working, and have it updating with AJAX. I love it. My charts don’t print though (File > Print). I can print your version, and the charts from OFC the site. I don’t know what I managed to do wrong. Have you seen this?
Asking a question out loud is a sure-fire way to finally figure it out on your own. I played around with tutorials on the OFC site, and they all worked. So I compared the swfobject.embedSWF bit between my code and theirs. It turns out that when I had both the data-file AND the wmode pieces in there the chart is no longer printable - in any example or in the rails app.
Since the data-file piece is kind of important, I dropped the wmode piece. From what I can tell on the Adobe site it’s not really necessary anyway.
I am thinking that this may be an issue with the SWF itself, so I will post this to that forum as well.
Thanks for the great plugin!
I was also getting the 2032 error when trying to load the chart on a secure page (HTTPS). After a lot of searching, I found that you have to add a couple of headers to the file that returns the data to the chart.
In PHP:
header("Cache-Control: cache, must-revalidate");
header("Pragma: public");
FYI, i’ve found that OFC2 doesn’t work with the "json_pure" gem.
In the OpenFlashChart module, ‘to_s’ is aliased via:
"
alias_method :to_s, :render
"
‘render’ itself calls ‘to_json2′, which does:
"
def to_json2
self.instance_values.to_json
end
"
Now ‘intstance_values’ should return a Hash, but this (somehow as i haven’t debugged it that far) would end up hitting this section of code in the "json_pure" gem:
"
def to_json(*) to_s.to_json end
"
That in turn would end up calling *back* in OFC via the ‘to_s’ method and call ‘render’ again. I don’t think this is intentional. In the end instead of getting JSON like this:
{"y_axis": {"steps": 42}}
you get:
{"y_axis":"{\"steps\":42}"}
The former returns a "y_axis" object that contains a "steps" object, where the "steps" object’s value is 42. The latter returns a "y_axis" object whose value is "{"steps":42}", which causes a flash error (which makes sense as the JSON is bogus with respect to what OFC is expecting).
So a couple of things:
1) *pretty* pretty please document this (until it is fixed)
2) relying on aliasing ‘to_s’ seems shady as this is called explicitly and implicitly from many places. Seems like coming up with a unique name would be better.
3) being nit picky here, but naming a method "render" also cause name collisions - but i don’t believe this causes any real errors - just a pain to search for potential bugs.
I’m wondering, on the main page of the project (http://pullmonkey.com/projects/open_flash_chart) if I do right click on any chart I can see the option "Print Chart…".
In my version it’s only "save image locally".
How can I change this option in my version?? Because I want the "Print Chart" option.
Thanks you
Alex
Thanks for the great charts,
I just wanted to know if these can be converted in image so those can be printed through pdf. As the pdf also contains other related data which should be printed along with charts.
I also looked at print chart option but that will not go with my requirement.
Is there any option which can help me to convert OFC in image for embedding that to pdf?
It looks like there’s NO WAY to attach a line to the right Y axis in a chart. I’ve tried setting "line.axis = "axis"" like it is document in the JSON with no luck. Any ideas?
Oops, I mean I tried setting line.axis = "right" or bar.axis = "right" with no success.
Fixed! I upgraded OFC and cleared all caches. Pie charts have been improved also. Thank you for the library!
I was not able to get the plugin work in the IE ,this is what I had to do to make it work. Download the latest swfobject.js from http://code.google.com/p/swfobject/
The latest open-flash-chart.swf from
http://sourceforge.net/project/showfiles.php?group_id=201148
And I had to change the line in open-flash-chart-object.rb
#div_name = "flash_content_#{special_hash}"
I think instead of using flash_content_#{special_hash} for generating unique div ids you can simple use
div_name = "flash_content_#{obj.object_id.to_s}"
where obj is a any object or you can substitute the part after flash_content with sha1 digest.
I was using IE &,may be the same problem exists in IE 8 too.
PM plugin for OFC is really gooooooood job!!
I’m now using the latest plugin fot open-flash-chart-ii like http://pullmonkey.com/2009/4/30/open-flash-chart-ii-fully-automated introduced, but I cannot make x_lable displayed even with the sample stacked_bar_chart under vendor\plugins\open_flash_chart\lib\ofc\examples.
Any thoughts for this? Is there any way to achieve this?
At last, Charlie, thanks for your guys’ great job!
Hi,
I tried your plugin but i m stuck with a problem,
the graph_code function return this string :
{title: {text: "MY TITLE"}, elements: [{type: "bar_glass", values: [1, 2, 3, 4, 5, 6, 7, 8, 9]}]}
And so it s not working (check the "")… i ve got a json parse error
if i manually render that ;
{"title": {"text": "MY TITLE"}, "elements": [{"type": "bar_glass", "values": [1, 2, 3, 4, 5, 6, 7, 8, 9]}]}
It works…
So what s going on ?
Thanks for the help
Really wan to explore use of this charting but falling at first hurdle with the following install error:-
Any help much appreciated.
C:\InstantRails\rails_apps\isms>ruby script\plugin install http://svn.pullmonkey.com/plugins/trunk/open_flash_chart/
C:/InstantRails/ruby/lib/ruby/1.8/net/http.rb:560:in `initialize’: Bad file descriptor - connect(2) (Errno::EBADF)
from C:/InstantRails/ruby/lib/ruby/1.8/net/http.rb:560:in `open’
from C:/InstantRails/ruby/lib/ruby/1.8/net/http.rb:560:in `connect’
from C:/InstantRails/ruby/lib/ruby/1.8/timeout.rb:48:in `timeout’
from C:/InstantRails/ruby/lib/ruby/1.8/timeout.rb:76:in `timeout’
from C:/InstantRails/ruby/lib/ruby/1.8/net/http.rb:560:in `connect’
from C:/InstantRails/ruby/lib/ruby/1.8/net/http.rb:553:in `do_start’
from C:/InstantRails/ruby/lib/ruby/1.8/net/http.rb:542:in `start’
from C:/InstantRails/ruby/lib/ruby/1.8/open-uri.rb:242:in `open_http’
… 20 levels…
from C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
from C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require’
from script/plugin:3
Is it possible to set the y_label color? The set_y_label_style method isn’t working for me. Thanks for all the great work on this plug-in Charlie!
How would you recommend one URL (link) pulling up two different charts?
All I’m getting is a blank page. I’ve followed the directions and tried installing it multiple time, but no luck.
swfobject.embedSWF(”/open-flash-chart.swf”, “flash_content_1ocFipX6″, “600″, “300″, “9.0.0″, “expressInstall.swf”,{”data-file”:”%2Ftest_it%2Fgraph_code”});
Andrew -
Did you include the swfobject.js in your view?
Any javascript errors?
Also, provide the output of http://your_domain.com/test_it/graph_code
My view contains but I’m getting a “swfobject is not defined” error.
graph_code output:
{”title”: {”text”: “MY TITLE”}, “elements”: [{"type": "bar_glass", "values": [1, 2, 3, 4, 5, 6, 7, 8, 9]}]}
Thanks for the quick reply, I’m really looking forward to using this.
I managed to get rid of the swfobject not defined error by using
But still no graph.
Is open-flash-chart.swf in your RAILS_ROOT/public directory?
Yeah, it’s there. I’ve gone through your instructions multiple times, I’m at a loss.
Well, feel free to package up your example and email it to me - charlie - at - this domain, I will take a look.
Is there a way to make the labels on the x-axis go down to the next line instead of scrolling horizontally forever? I’m having a problem with overlapping because my labels on the X-axis have somewhat long names. If not, is there a way to make the text that pops up when you scroll over a bar different from the text thats on the corresponding x-axis label? Thanks alot
Like to implement this on Sinatra instead of Rails. Is it possible?
Copied over the .swf and .js files to public and Javascript directory.
The codes for file ofc2.rb in the top level main dir :-
require ‘rubygems’
require ’sinatra’
get ‘/’ do
@graph = open_flash_chart_object(600,300, graph_code)
haml ‘%script{:type => “text/javascript”,
:src => “/javascripts/swfobject.js”}
%p= @graph’
end
def graph_code
title = Title.new(”MY TITLE”)
bar = BarGlass.new
bar.set_values([1,2,3,4,5,6,7,8,9])
chart = OpenFlashChart.new
chart.set_title(title)
chart.add_element(bar)
render :text => chart.to_s
end
Basically ofc2.rb runs and http://localhost:4567/ generates below error msg:-
NameError at /
uninitialized constant Title
* file: ofc2.rb
* location: graph_code
* line: 13
What was missed?
Thanks for any suggestions!
Ad
@Ad - I am not too familiar with Sinatra, but you might have to include OpenFlashChart if the plugin’s init.rb file does not get processed. Test that theory by doing OpenFlashChart::Title.new instead of just Title.new.
Let me know how it goes.
I guess you are right.
The error on the browser now becomes
NameError at /
uninitialized constant OpenFlashChart
The ruby file simply doesn’t recognize Title or OpenFlashChart.
If i copied the plugin file and runs, this is the error i got on console:-
$ sudo script/plugin install http://github.com/pullmonkey/open_flash_chart.git
script/plugin:2:in `require’: no such file to load — script/../config/boot (LoadError)
from script/plugin:2
Apparently, i am neither a rails not sinatra expert, just s.o figuring out. So, thanks Charlie for your help anyway.
Any more ideas?
(Sinatra is pretty straightforward compared to rails, it’s like just a one page readup here http://www.sinatrarb.com/intro.html but figuring the transition from rails may not…)
Ok, I looked at sinatra a bit. The feeling that I get is that you won’t be able to use many plugins with sinatra since they usually provide mixins for activerecord, actioncontroller and actionview.
But that doesn’t mean you can’t try -
The very first thing would be to explicitly require the init.rb file of the plugin.
That would be like this - require “path_to_ofc_plugin/init”
Before that, you will need to get the plugin, you can not use ./script/plugin that does not exist for sinatra, just in a rails root directory. So, instead, you can just download it from my github.
Next, you should probably edit the init.rb file and remove all the includes, lines 3 - 9. Since in sinatra I don’t thikn you have actionview or AR or actioncontroller. If you do then you can leave those lines.
NOW, everywhere I do stuff like Title, or what not, you will do OpenFlashChart::Title.
Give that a shot and keep us updated.
I have updated to latest release Open Flash Chart (version 2) and found many bugs:
1. Many Lines and dots be not shown by swf(example LineHollow and other except Line).
2. Tooltip is not shown for open-flash-chart.swf. but open-flash-chart-bar-clciking.swf it is shown, but Y-Right-axis is not working.
Thanks
Interesting - do you have a couple examples that break? Either post them here, on gist or pastie.
Thanks.
thanks for this plugin! is really great but i have one little problem here… i’m having this trouble trying to display my x label into my tooltip, this is my code:
def show
@graph = open_flash_chart_object(520,300,”/dashboard/graph_code”)
end
def graph_code
@bills = current_user.bills.all(:order => ‘previous_meter_reading_date DESC’, :limit => 12).reverse
bar = BarGlass.new
bar.values = current_user.consumption_per_day_history.map { |b| b[:value] }
bar.set_key(’My consumption’,10)
bar.tooltip = “[#x_label#] #key#:#val# kWh/day”
bar.colour = ‘#89C33E’
vals = current_user.consumption_per_day_history.map { |b| b[:value] }.reverse
#set the chart style and chart settings
title = Title.new(”Consumption kWh/day”)
x_axis = XAxis.new
x_axis.set_range(0, @bills.size, 1) # set the number o
x_axis.colour = ‘#C0C0C0′
x_axis.set_grid_colour(’#FFFFFF’)
labels = XAxisLabels.new
labels.labels = current_user.consumption_per_day_history.map { |b| “#{Date::ABBR_MONTHNAMES[b[:month]]} #{b[:year]}” }
labels.rotate = 320
x_axis.labels = labels
max = 0
@bills.each do |bill|
max = bill.consumption_per_day if bill.consumption_per_day > max
end
y_axis = YAxis.new
y_axis.set_inner_bg_colour( ‘#E3F0FD’, ‘#CBD7E6′, 90 )
y_axis.set_range(0, max, 2)
y_axis.colour = ‘#C0C0C0′
y_axis.set_grid_colour(’#C0C0C0′)
# x and y leyends
x_legend = XLegend.new(’Month and year’)
x_legend.set_style(’{font-size: 14px; color: #89C33E}’)
y_legend = YLegend.new(”kWh”)
y_legend.set_style(’{font-size: 20px; color: #89C33E}’)
t = Tooltip.new
t.set_shadow(true)
t.stroke = 4
t.colour = ‘#89c33e’
t.set_background_colour(”#EEEEEE”)
t.set_title_style(”{font-size: 13px; font-weight: bold; color: #89C33E;}”)
t.set_body_style(”{font-size: 11px; color: #000000;}”)
chart = OpenFlashChart.new
chart.title = title
chart.bg_colour = ‘#FFFFFF’
chart.add_element(bar)
chart.set_tooltip(t)
chart.x_axis = x_axis
chart.y_axis = y_axis
render :text => chart.to_s
end
so the tooltip’s [x_label#] is always returning blank, can somebody please help me????
Dang, that should work. Can you remove the square brackets, see if that helps?
@charlie thanks for your reply but anyway i tried what you said (removing the brackets) so my tooltip now looks like:
bar.tooltip = “#key#: #x_label# #val# kWh/day”
also tried just with…
bar.tooltip = “#x_label#”
and still can’t get the x_label shown on the tooltip.
any ideas???