PullMonkey Blog

19 Aug

Open Flash Chart Plugin for Rails

Leave your comments here for the new release.

Open flash chart is awesome it is used to create some really nice, sharp looking graphs.

Check out the Open Flash Chart Project here.

I have ported the php/perl/python code to ruby for use with Rails.

I have some examples on my Projects Page.

35 Responses to “Open Flash Chart Plugin for Rails”

  1. By francis sinson on Aug 19, 2007 | Reply

    yo,<br/><br/>Saw some gotcha’s:<br/>1. there’s a missing closing " in the self.swf_object method.<br/><br/>2. Add the CGI.escape to the url :)<br/><br/>thanks:)<br/>/franee

  2. By charlie on Aug 19, 2007 | Reply

    Franee,<br/>Thank you, great catches - did as you requested, tested and committed.

  3. By scott on Aug 19, 2007 | Reply

    thanks for the great plugin charlie :)

  4. By charlie on Aug 19, 2007 | Reply

    Not a problem Scott, just let me know if you run into any issues, or you can track them here - <a href="http://code.google.com/p/rails-open-flash-chart-plugin/issues/list">http://code.google.com/p/rails-open-flash-chart-plugin/issues/list</a>

  5. By scott on Aug 19, 2007 | Reply

    I’ve posted two issues and a patch at the google code site.

  6. By charlie on Aug 19, 2007 | Reply

    Thanks Scott, I will take care of those for you.

  7. By charlie on Aug 19, 2007 | Reply

    Scott, see if my fixes work for you. I used your fix for the "axis" => "method" issue. I did not use your solution for the x_axis_steps issue, instead I removed nil array elements before joining via compact b/c that would impact the 3d graphing, which I do not personally use either.<br/>Thank you.

  8. By Moisés on Aug 19, 2007 | Reply

    Hi, thanks for the plugin. I am new in rails, but i have one questions:<br/><br/>Wy not add:<br/><br/>class OpenFlashChart<br/> <br/> attr_accessor( :y_min, :y_max …<br/><br/>to make all the attributes read/write accessible? <br/><br/><br/>

  9. By charlie on Aug 19, 2007 | Reply

    Moisés - Good question. One reason that I did not open up all the attributes in that way is because of documentation. To enable the user to use the variables in this way would require much more documentation. If you look closely, you will see that some of the setter methods do a bit of data manipulation that the user (of the plugin) may not expect. <a href="http://teethgrinder.co.uk/open-flash-chart/">Teethgrinder</a> has already done a great job documenting this project. So, if I keep things simple and provide the same usability, then users of the plugin can easily refer to what he has already provided in terms of examples and documentation. Hope this makes sense.

  10. By Adrian on Aug 19, 2007 | Reply

    Multi line example (http://pullmonkey.com/projects/open_flash_chart/multi_line) has a little problem: in controller there is a variable @output and in the view the variable is @graph. Should have the same name

  11. By charlie on Aug 19, 2007 | Reply

    @Adrian, fixed it, thank you.

  12. By Pete on Aug 19, 2007 | Reply

    It looks like the y_legends don’t work. x_legends work, is this just a rendering problem?

  13. By charlie on Aug 19, 2007 | Reply

    @Pete - Thanks, fixed it. Get the new version of the library from here - http://rails-open-flash-chart-plugin.googlecode.com/svn/trunk/lib/open_flash_chart.rb

  14. By Adrian on Aug 19, 2007 | Reply

    Looking at http://teethgrinder.co.uk/open-flash-chart/gallery-null.php, I think you should modify line 53 in open_flash_chart.rb from _@data << ‘&values=’ + data.join(’,') + "& \n"_ to _@data << ‘&values=’ + data.map{ | x | x.nil? ? ‘null’ : x }.join(’,') + "& \n"_ (and line 55 same way). If my values (y axis) are [1, nil, 3], you give to swf …&values=1,,3… and the graphic doesn’t look fine. You should pass to swf …&values=1,null,3… to work as expected.

  15. By Adrian on Aug 19, 2007 | Reply

    I think another problem is when you try to use set_x_axis_steps. It doesn’t work until you call ofc.set_x_axis_3d( nil ) to overwrite x_axis_3d to nil, from ”. x_axis_3d has to be nil, so the output is …&x_axis_steps=3&…, otherwise (with x_axis_3d = ”) the output is …&x_axis_steps=3,&… and it doesn’t work.

  16. By charlie on Aug 19, 2007 | Reply

    @Adrian, thank you for using the plugin and reporting the problems, I will fix them as soon as I can and will let you know, shouldn’t be longer than a day or two.

  17. By charlie on Aug 19, 2007 | Reply

    @Adrian, I fixed the two problems, first issue - I used your suggestion, and issue two - I default x_axis_3d to nil instead of ”. Thanks and let me know if this works for you. You can get the new release from the <a href="http://rails-open-flash-chart-plugin.googlecode.com/svn"> google code repository</a>.

  18. By Adrian on Aug 19, 2007 | Reply

    Till I get the new version of the plugin, there’s another issue: I guess the *.swf in your rails plugin is not the latest version. It doesn’t work for set_tool_tip. If I replace the open-flash-chart.swf from rails plugin with the one from http://sourceforge.net/project/showfiles.php?group_id=201148, tool tips are fine.

  19. By Juan Pablo on Aug 19, 2007 | Reply

    In all scripts, i got the following error<br/><br/>chart_controller.rb:19: syntax error, unexpected ‘=’, expecting kEND<br/> render :text =&gt; ofc.render<br/> ^<br/><br/>I’m learning how to code Ruby scripts, and i don’t know how to figure out this issue. I’ll try to build my own controller to show graphs on my rails application, but i don’t know if this problem is related with some configuration or version of my RoR.<br/><br/>Thanks.

  20. By charlie on Aug 19, 2007 | Reply

    @Juan, I just recently converted all my examples (i.e., http://pullmonkey.com/projects/open_flash_chart/bar_chart_filled) to use coderay. After seeing your comment, I looked to see what my example shows and it had "render :text =&amp;gt;", where &amp;gt; should be >. You might want to check line 19 of your controller and change "render :text =&amp;gt;" to "render :text =>". In fact I just changed my code to reflect what I think you might have and I got the exact same error. Otherwise, if this is not the problem, then post your code here and I will gladly help.

  21. By Juan Pablo on Aug 19, 2007 | Reply

    Charlie,<br/><br/>it works fine for me now. Some classmates help me to solve the problem. Now i can test some graphs, looks great!!<br/>Now i’m trying to figure out how to make other types of graphs, like Pie Charts, 3D Bar Chart and so on.<br/> <br/>Thank you so much.

  22. By Søren on Aug 19, 2007 | Reply

    Hi Charlie<br/><br/>Thanks alot for the plugin!!!<br/><br/>At the moment I am using it to make a pie chart, which is awesome. I have been messing around with the settings, but have had some problems. Maybe you can help me: <br/><br/>1) Is et possible to scale only the chart, to leave more room for my labels (at the moment part of them aren’t visible)?<br/>2) Can I remove the yellow standard background? I have tried to use set_inner_background, but without success.<br/><br/>Any help will be much appreciated.<br/><br/>Thanks!<br/>- Søren<br/><br/><br/>

  23. By Søren on Aug 19, 2007 | Reply

    I don’t know how missed it, but figured out how to change the background: ‘.set_bg_color("#FFFFFF")’.<br/><br/>I still haven’t figured out how to do the scaling of the pie alone though…<br/><br/>Thanks<br/>- Søren

  24. By zonked on Aug 19, 2007 | Reply

    ya saved my life dude !!………thanks! :)

  25. By subaqua on Aug 19, 2007 | Reply

    I’m stumped…<br/><br/>I’m using rails 2.0.2. I created a new controller called chart. I put the "bar_chart_glass" code in from your example and now all I get is:<br/><br/>ActionController::RoutingError (No route matches "/open-flash-chart" with {:method=>:get}):<br/><br/>in my development.log file. I have open-flash-chart.swf in my /public directory and it’s readable…. <br/><br/>Any ideas?<br/>

  26. By charlie on Aug 19, 2007 | Reply

    @subaqua- I would have to see more of your code to determine the actual problem. Let me know.

  27. By subaqua on Aug 19, 2007 | Reply

    @charlie<br/><br/>I found the problem; my mongrels were behind a proxying apache server, to solve the problem I had to copy the open-flash-chart.swf file to the doc-root on the apache server. This might not be the correct solution but for now it works.<br/><br/><br/><br/>

  28. By Tim on Aug 19, 2007 | Reply

    hi,<br/>thanks for this great plugin.<br/>I have still the problem that the IE doesn’t load the .swf .<br/>The funny thing is that everything works fine with firefox. <br/>Has anybody an idea?<br/>I tested with this configuration:<br/>IE version 6.0<br/>firefox version<br/>Flashplayer 9.0<br/>based on<br/>ruby 1.8.6<br/>Rails 1.2.6<br/><br/>

  29. By Christian von Kleist on Aug 19, 2007 | Reply

    After calling set_y_right_max(n), &y2_max=n& is not set in the output. I fixed it for my copy, but why is @y2_max set to "&y2_max=n& " instead of n?<br/><br/>Great plugin!<br/><br/>(BTW, some of your indents in flash_chart.rb are actual tabs instead of soft tabs.)

  30. By charlie on Aug 19, 2007 | Reply

    @Tim - I will look into it.<br/>@Christian - I am working on the new release right now, so these problems will hopefully be fixed.

  31. By Christian von Kleist on Aug 19, 2007 | Reply

    Cool! Good luck with the new release.<br/><br/>There is also a small problem in set_inner_background where @inner_bg_color2 should be @inner_bg_color_2.

  32. By Christian von Kleist on Aug 19, 2007 | Reply

    @y_label_style is missing from the output.<br/><br/>Is there a better place to leave notes like this, like a DevjaVu account?

  33. By charlie on Aug 19, 2007 | Reply

    Yes, you can leave them with the google code issue tracker - http://code.google.com/p/rails-open-flash-chart-plugin/issues/list&lt;br/&gt;Thanks for your help.

  34. By liam on Aug 19, 2007 | Reply

    Are you still working on a new release? I’m just looking to jump into this now, but was wondering if it would be worth waiting a bit…thanks!

  35. By charlie on Aug 19, 2007 | Reply

    @liam - 1.9.7 is the latest release - http://pullmonkey.com/2008/2/4/open-flash-chart-plugin-for-ruby-on-rails-1-9-7-release
    I keep my release current with the php version - http://teethgrinder.co.uk/open-flash-chart/download.php
    Now, is probably a good time to get familiar. Enjoy!

Sorry, comments for this entry are closed at this time.