Open Flash Chart II Plugin for Ruby on Rails (OFC2)
July 23rd, 2008 by charlie
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:
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.
July 25th, 2008 at 07:39 AM 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)
July 25th, 2008 at 10:58 AM
@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.
July 25th, 2008 at 12:30 PM Hi,
I keep getting:
"Open Flash Chart
IO ERROR
Loading test data
Error #2032"
Any idea how to debug that ?
July 25th, 2008 at 12:30 PM Hi,
I keep getting:
"Open Flash Chart
IO ERROR
Loading test data
Error #2032"
Any idea how to debug that ?
July 25th, 2008 at 01:33 PM
@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.
July 27th, 2008 at 10:37 AM 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)
July 27th, 2008 at 11:31 AM No me puedo hacer.. alguien habla español????? I cannot do!! Help! The graphs are not displayed
July 28th, 2008 at 03:44 AM Beautiful! Works perfectly in Safari 3 on Mac OS 10.5.4.
Thanks
Till
July 28th, 2008 at 07:46 AM 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.
July 28th, 2008 at 10:15 AM
@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
July 28th, 2008 at 10:20 AM
@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.
July 29th, 2008 at 01:39 PM Thanks a lot for all ! Could you please put an example for pie charts ?
July 29th, 2008 at 04:28 PM
@Chipster - here is a pie chart example - http://pullmonkey.com/2008/7/29/open-flash-chart-ii-pie-chart
July 29th, 2008 at 11:26 PM 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.
July 30th, 2008 at 01:34 AM
i accumulate all the errors :/
Plugin not found: ["git://github.com/pullmonkey/open_flash_chart.git"]
it's normal ?
July 30th, 2008 at 02:26 AM
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"
<%= @graph %>
can you tell me my errors ?
July 30th, 2008 at 09:51 AM
@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.
July 30th, 2008 at 09:56 AM
@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.
July 30th, 2008 at 10:35 AM @Victor I had the same problem i resolved by replacing in view :
by :
<% javascript_include_tag "swfobject" %>
July 30th, 2008 at 10:45 AM Sorry, i meaned replacing the original " standard " javascript file declaration by rails tag. Hope it could help
July 31st, 2008 at 02:13 AM
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 :/
July 31st, 2008 at 10:05 AM
@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.
July 31st, 2008 at 03:55 PM 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>
</head>
<body>
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"});
<noscript>
<object height="300" width="600">
<param />
<param />
<param />
<param />
<embed src="/test-it/open-flash-chart.swf?data=%2Ftest_it%2Fextra_tt" height="300" width="600" />
</object>
</noscript>
</body>
</html>
July 31st, 2008 at 03:56 PM sorry, here is my output from my view:
<html>
<head>
</head>
<body>
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"});
<noscript>
<object height="300" width="600">
<param />
<param />
<param />
<param />
<embed src="/test-it/open-flash-chart.swf?data=%2Ftest_it%2Fextra_tt" height="300" width="600" />
</object>
</noscript>
</body>
</html>
August 1st, 2008 at 01:13 AM
when i am in the case of the flash object is loaded ,this is the html return :
view.html //
<object height="300" width="600">
<param />
</object>
1
2 swfobject.embedSWF("/open-flash-chart.swf", "flash_content_1217574332.47648", "600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Fmigrate%2Fgraphcode"});
3
<noscript> <object height="300" width="600"> <param /> <param /> <param /> <param /> <embed src="/open-flash-chart.swf?data=%2Fmigrate%2Fgraphcode" height="300" width="600" /> </object> </noscript>
August 1st, 2008 at 01:16 AM
when i am in the case of the flash object is loaded ,this is the html return :
view.html //
<object height="300" width="600">
type="application/x-shockwave-flash" data="/open-flash-chart.swf" style="visibility: visible;">
<param />
</object>
1
2 swfobject.embedSWF("/open-flash-chart.swf", "flash_content_1217574332.47648",
"600", "300", "9.0.0", "expressInstall.swf",{"data-file":"%2Fmigrate%2Fgraphcode"});
3
<noscript>
<object>
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 />
<param />
<param />
<param />
<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>
August 1st, 2008 at 01:31 AM 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
August 1st, 2008 at 10:49 AM
@andrew - here is a line graph example - http://pullmonkey.com/2008/8/1/open-flash-chart-ii-line-graph
August 1st, 2008 at 11:07 AM
To insert HTML/ruby/other code into the comments, you can do this:
That should do it ...
August 1st, 2008 at 11:11 AM
So here is Victor's HTML:
August 1st, 2008 at 11:17 AM And for comparison with Victor's here is what I get:
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?
August 2nd, 2008 at 09:49 AM 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?
August 2nd, 2008 at 10:46 AM
@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.
August 2nd, 2008 at 03:05 PM 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?
August 2nd, 2008 at 04:17 PM
@Gallo, would you mind posting your code and I will see if I can help.
August 3rd, 2008 at 11:52 AM 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><barglass:0xa6da4e8>],
@title=#<title:0xa6da4fc>>
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
August 3rd, 2008 at 03:48 PM
@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.
August 3rd, 2008 at 10:20 PM 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.
August 4th, 2008 at 03:12 AM 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?
August 4th, 2008 at 03:45 AM My fault, had an old version of open-flash-chart.swf in my public folder! :)
August 4th, 2008 at 10:50 AM
@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.
August 5th, 2008 at 01:10 AM
my controler :
<filter:code>
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 ...
:(
August 5th, 2008 at 01:13 AM
my controler :
i don't understand why i have this error ...
:(
:D
August 5th, 2008 at 11:11 AM
@Victor - here is one thing you should try:
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.
August 6th, 2008 at 01:14 AM
this is my html code with your controlor :
and i think i have the latest swf (size : 274Ko)
and i always the error #2032.
August 6th, 2008 at 01:27 AM
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
August 6th, 2008 at 01:58 AM 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 ... :/
:$
August 6th, 2008 at 07:37 AM
@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.
August 6th, 2008 at 08:15 AM 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 :/
August 6th, 2008 at 08:22 AM
@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.
August 6th, 2008 at 01:24 PM In your opinion, what's the best movie ever created?
August 7th, 2008 at 02:09 AM
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
August 7th, 2008 at 06:37 AM
@Victor - let's start simple:
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():
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:
8) Browse to http://yourdomain/test_it/test_one - you should see the JSON that we manually entered
9) Browse to http://yourdomain/test_it - you should see glass bar graphs
Let me know.
August 7th, 2008 at 06:40 AM
@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?
August 7th, 2008 at 06:49 AM
@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
August 7th, 2008 at 07:13 AM
@Victor - Both - in a new project just as a base case then in your plugin of redmine.
August 10th, 2008 at 12:04 PM 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?
August 11th, 2008 at 02:15 AM
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'
:(
August 11th, 2008 at 09:17 AM
@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?
August 11th, 2008 at 09:26 AM
@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?
August 12th, 2008 at 08:46 AM
I haven't find a help in your URL :(
what do you want i clarify ? i don't understand do you want :/
August 12th, 2008 at 10:15 AM
@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.
August 15th, 2008 at 04:34 AM 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:0x37c8c1c>
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)
August 15th, 2008 at 06:32 AM 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:0x2c34748>
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!
August 15th, 2008 at 07:29 AM
@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.
August 15th, 2008 at 08:55 AM
@Christopher - I removed the protocol variable on accident :( Added it back, thanks for the catch.
August 15th, 2008 at 03:51 PM 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':
view 'main/index.html.erb':
Generated HTML:
Accessing http://localhost:3002/main/graph_code i get what seems to be the appropiate JSON:
August 15th, 2008 at 05:24 PM
@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.
August 16th, 2008 at 08:41 PM @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?
August 16th, 2008 at 11:47 PM
@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.
August 17th, 2008 at 01:52 AM 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.
August 17th, 2008 at 10:35 AM
@Totem - do you see graphs if you go here - http://pullmonkey.com/projects/open_flash_chart2 or do you still get the same error?
August 17th, 2008 at 01:16 PM
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
August 17th, 2008 at 03:02 PM
@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.
August 17th, 2008 at 08:10 PM Same thing. FF is fine, IE gives the error.
I'm surprised that no one else is having a similar problem.
August 17th, 2008 at 09:53 PM
@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.
August 18th, 2008 at 12:14 PM
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
August 18th, 2008 at 02:00 PM
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
August 19th, 2008 at 12:18 AM
@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.
August 19th, 2008 at 08:57 AM
@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.
August 19th, 2008 at 10:09 AM 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?
August 21st, 2008 at 12:05 PM Just in case someone else has this problem: instead of the gem 'json' you need to require 'activesupport'
August 22nd, 2008 at 04:03 AM 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
August 22nd, 2008 at 08:18 AM
@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.
August 24th, 2008 at 11:51 AM 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
August 24th, 2008 at 12:06 PM 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
August 24th, 2008 at 10:40 PM
@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
(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:
thanks
August 24th, 2008 at 10:43 PM BTW, where there's something missing from my previous post, I typed < div > without the spaces, but it got chewed...
August 24th, 2008 at 11:15 PM
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...)
August 25th, 2008 at 11:48 AM 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.
August 25th, 2008 at 12:09 PM 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?
August 25th, 2008 at 12:38 PM This is the output from my safari/firefox 3.0.
I can't see any flash. Can I get help?
August 25th, 2008 at 12:49 PM
This is other output from other machine, your test_it example. Still I am not seeing anything other than a blank page
August 25th, 2008 at 03:58 PM
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
August 26th, 2008 at 05:36 PM
@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:
August 26th, 2008 at 05:46 PM
@hhh - Do you have javascript enabled? Can you see my graphs? Your JSON output looks right.
August 26th, 2008 at 05:48 PM
@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.
August 28th, 2008 at 03:29 PM
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
August 31st, 2008 at 09:30 PM
@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!
September 1st, 2008 at 03:14 PM
@Charlie, it looks like there's no way to setup the title style. In the 1.9.x versions I see:
but in version 2, I only see:
any reason for this?
thanks!
September 1st, 2008 at 03:14 PM
@Charlie, it looks like there's no way to setup the title style. In the 1.9.x versions I see:
but in version 2, I only see:
any reason for this?
thanks!
September 2nd, 2008 at 07:26 PM @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:
Hope that helps.
September 3rd, 2008 at 08:48 AM 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
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 :-)
September 3rd, 2008 at 09:02 AM Ahh! I had forgotten to copynpaste the js file and put an = (<%= javascript_... %> Works great! Very nice sample graph :-)
September 3rd, 2008 at 05:02 PM 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?
September 4th, 2008 at 08:11 AM 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.
Here is the StaticPageController
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.
September 4th, 2008 at 09:47 AM
@Jesse - no need for a donation. I sent you an email.
September 5th, 2008 at 09:33 AM
I'll be interested in how this was done too. :-)
Could you share the information?
September 5th, 2008 at 10:35 AM
@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.
September 7th, 2008 at 10:17 PM 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.
September 8th, 2008 at 10:20 AM
@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
September 14th, 2008 at 11:22 AM 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]}]
September 14th, 2008 at 08:00 PM
@Harry - There is the Rails OFC I plugin that does work with 1.2.x - http://pullmonkey.com/projects/open_flash_chart
September 15th, 2008 at 06:10 AM 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>
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>
def graph_code
vias = self.getVias
puts vias #always change to 0
#some other code
end
< /filter:code>
September 15th, 2008 at 06:12 AM 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
And here I get it and the value of vias became '0'
September 15th, 2008 at 09:16 AM
@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: