Open Flash Chart Plugin for Ruby on Rails
February 4th, 2008 by charlie
Update: Version 2 of Open Flash Chart is available. Examples for version 2 are here.
I just finished converting version 1.9.7 of Open Flash Chart over to ruby, for use with rails.
Check out what I can do now :) I can customize my tooltips:
Extra Tool Tips
View Source Code
More examples can be found on my Open Flash Chart Projects page.
Don't forget to check out the original - http://teethgrinder.co.uk/open-flash-chart/.
February 5th, 2008 at 10:08 AM Charlie
This is great stuff. I tried to install your latest changes, but when I use the plugin script I just see the older release (no Line class in open_flash_chart.rb). Will you be committing your changes to SVN soon?
Thanks,
Scott
February 5th, 2008 at 12:08 PM Scott - glad you like it. The changes should already be in SVN. I just checked - svn export http://svn.pullmonkey.com/plugins/trunk/open_flash_chart
February 5th, 2008 at 12:09 PM Sorry, script/plugin install <same>. What was it that you tried? Did you get any errors saying that the plugin already exists? Try moving the old version out of the way then plugin install it.
February 12th, 2008 at 10:35 PM Hi, I'm wondering if it is possible to graph a trend line with missing values. For example, if I want to plot the value of something every 10 minutes for 6 hours, but a few of the timepoints are missing. Thanks!
February 13th, 2008 at 08:39 AM @ilikerice - I think I understand what you are asking, but I am not sure. You have null values and probably a line graph and you want the line graph to contain null data but not to drop down to 0. If I understand you correctly you will want to check out this graph - http://pullmonkey.com/projects/open_flash_chart/view_source_code/null_data
You pretty much just put the string 'null' for your null data points and the swf object will pick it up. Note that there are points where data exists and no points where the data is null, but the line continues with the trend.
February 14th, 2008 at 03:27 PM Theres a bug in the pie gradient code.
if !gradient
@pie += ",#{!gradient}"
end
should be
if !gradient
@pie += ",#{gradient}"
end
or better yet, the method can just be defined as follows:
def pie(alpha, line_color, style, gradient = true, border_size = false)
@pie = "#{alpha},#{line_color},#{style},#{gradient}"
@pie += ",#{border_size}" if border_size
end
February 14th, 2008 at 03:45 PM I'm confused. The code in subversion is way different than the code in the 1.9.7 release available on source forge (the 1.9.7 zip file). This is fine but the code listed here does not appear to work with the plugin code available in the tarball from sourceforge.
This code does work with the subversion code.
Also, just a nit... Can you PLEASE remove all the tabs from the open_flash_chart.rb file ? Indentation in ruby is by convention supposed to be two normal spaces per indent level. If you give me commit access I'd be happy to clean it up for you :-)
Thanks for all your work, this stuff is awesome!
February 14th, 2008 at 04:50 PM Why delete valid comments? Your pie chart implementation has a bug in the gradient logic. I sent you the fix.
February 15th, 2008 at 01:42 PM Slathered1 - I did not delete your comment that I can recall, sorry if I did. I still see the code fix. Are you sure I deleted it, can you tell me what it was about? I am going to look in to your suggestion either way.
February 15th, 2008 at 01:56 PM subaqua - can you give me an example of what is different? I will gladly fix it. Also, you have to realize I am a step behind from the zip file release. I get the zip of 1.9.7 release and then update my code accordingly and update my repository and their sourceforge repository. That means that the zip you download from sourceforge is my 1.9.6 version. And yes there is a huge difference there. If you want to go through sourceforge you will have to get it from trunk, not download.
February 15th, 2008 at 02:03 PM Slatherd1 - I mimic the 1.9.7 release so if I have a bug, then release 1.9.7 has a bug, can you explain to me what this is affecting exactly? Give an example where it fails. Then I will be able to fix it. Thank you.
February 15th, 2008 at 02:20 PM subaqua - I am aware of the 2 space convention and follow it religiously. However, I use vi so everything looks good to me. I have it setup to convert tabs to 2 spaces. Anyway, this should do the trick - sed "s/^\t/ /" lib/open_flash_chart.rb, so now check it out.
February 17th, 2008 at 01:14 PM Awesome work, keep it up!
February 18th, 2008 at 09:23 AM charlie: thanks! hopefully you can check it into SVN this way; otherwise my svn diff's always show differences. I have been doing global search and replace each time before doing my diffs against your code. Having it at 2 spaces instead of using tabs will make the code look the same to everyone since not everyone uses vi, vim, emacs, textedit , etc .
You rock, thanks for the help.
February 18th, 2008 at 09:45 AM charlie: yes, I will give you an example. In your examples on this page, you use:
g = Graph.new
And in subversion, the plugin lib/open_flash_chart.rb starts out with 'Class Graph ...'
If you get the 1.9.7 release tarball from sourceforge, the lib/open_flash_chart.rb starts out with:
class OpenFlashChart
and there is no "Graph" class. It appears to be a slightly older copy.
So my point was just that it looks like "1.9.7" examples on this page are actually only going to work with the subversion code and not the 1.9.7 code which is being made available on the source forge openflashchart web site.
Hope this helps. Take care.
February 18th, 2008 at 09:48 AM Charlie: never mind my last post as I've read your original response. I wasn't aware that the pull-monkey directory in the sourceforge release was by design version n-1. LOL.... Good, I'm not going crazy :-)
February 18th, 2008 at 01:52 PM @subaqua - I will do my best to convert tabs to spaces. And, yes the official zip contains release n-1 :)
February 19th, 2008 at 02:05 AM Many thanx for this great plugin!
It was easy to use and works like a charme.
Keep up this great work!
Bye !
February 21st, 2008 at 01:18 AM Nice :-)
You have 13 months - :-D like it
February 21st, 2008 at 09:21 PM Yup, 13 months is a good thing. More pay checks, more time, more everything. It is because I went from 0..12 for some reason. I think I will leave it :)
February 22nd, 2008 at 06:52 AM I found some great tutorials on how to implement this in .net:
http://www.prestigedevgroup.com/tutorials.aspx
Here's an Ajax demo:
http://www.prestigedevgroup.com/tutorials/openflashchart/Demo/
February 22nd, 2008 at 11:08 AM just upgraded and am only seeing #tip# as a string instead of my setup label. have used your example code and still see the same behavior. below is my code:
def create_swingweight_graph
data_1 = Line.new(2, '#9933CC')
data_1.key('Page Views', 10)
data_2 = LineHollow.new(2,5,'#CC3399')
data_2.key("Downloads",10)
data_3 = LineHollow.new(2,4,'#80a033')
data_3.key("Bounces", 10)
(0..12).each do |i|
data_1.add_data_tip(rand(5) + 14, "(Extra: #{i})")
data_2.add_data_tip(rand(5) + 8, "(Extra: #{i})")
data_3.add_data_tip(rand(6) + 1, "(Extra: #{i})")
end
g = Graph.new
g.title("Many Data lines and Extra tooltips", "{font-size: 20px; color: #736AFF}")
g.data_sets << data_1
g.data_sets << data_2
g.data_sets << data_3
g.set_tool_tip('#tip#')
g.set_x_labels(%w(Jan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec))
g.set_x_label_style(10, '#000000', 0, 2)
g.set_y_max(20)
g.set_y_label_steps(4)
g.set_y_legend("Open Flash Chart", 12, "#736AFF")
render :text => g.render
end
February 22nd, 2008 at 04:06 PM @aaron, I had some of the code wrong, try the code I up there now. Also, you may have better luck removing the plugin and reinstalling it.
February 26th, 2008 at 03:11 PM I'm new to the whole RoR thing, do you have a example of pulling the stats out of the database? for like charting number of users over a x amount of time?
February 26th, 2008 at 05:02 PM All my examples are fairly static and non database driven. We can take the spoon sales graph as an example:
def view
@graph = open_flash_chart_object(500,250, '/projects/open_flash_chart/one', false, '/projects/')
end
def one
g = Graph.new
g.title("Spoon Sales", '{font-size: 26px;}')
# we only want 2007 spoon sales
spoon_sales = SpoonSale.find(:all, :conditions => "created_at <= '2007-12-31' and created_at >= '2007-01-01'")
spoon_sales_monthly_counts = []
(0..11).each do |month|
spoon_sales_monthly_counts << spoon_sales.select{|s| s.created_at.month == month + 1}.size
end
g.set_data(spoon_sales_montly_count)
g.set_x_labels(%w(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec))
g.set_y_max(60)
g.set_y_label_steps(6)
render :text => g.render
end
It has not been tested but the idea is there.
Hope this helps.
February 27th, 2008 at 06:56 PM Nice! This is more or less exactly what I've been looking for. Well done.
March 5th, 2008 at 01:07 PM Just downloaded your plugin (march 5) from your SVN repo and have a couple of patches. I can't find your contact info so am going to describe them here:
On line 819, width and height need to be width.to_s and height.to_s to avoid a "can't convert Fixnum to String" bug.
On line 200, "@inner_bg_color2" should be "@inner_bg_color_2"
Let me know if there's a better way to send this sort of stuff to you...
March 6th, 2008 at 07:44 AM Have a changerequest based on using javascript menus together with OFC.
The problem is that flash takes topmost z-index totally ignoring other objects z-index, which means that flash lies on top of the menu obscuring the view (and clicking it).
The "fix" for this is to set the flash components window mode to transparent (not sure if there are any sideeffects for setting this parameter).
In open_flash_chart.rb add the following lines:
Line 821:
out << 'so.addParam("wmode", "transparent");'
Line 833:
out << '<param />'
Since I don't know flash good enough to know the side effects for setting this parameter you might consider having this optional.
March 6th, 2008 at 12:11 PM A patch to support adding nil data instead of having to write it as "null".
http://pastie.caboo.se/162446
March 9th, 2008 at 11:22 AM @Philip H. -
Perfect, I have committed your changes. Thank you.
@Joachim F. -
I have also committed your changes, but took your suggestion of making it optional. As I have it now, you can turn on transparency like this (the default is false):
@graph = open_flash_chart_object(500,250, '/projects/open_flash_chart/one', false, '/', true)
Update your plugin and see if that works for you.
Thanks.
March 10th, 2008 at 06:12 AM That solution should work. But it looks like mephisto ate part of the code (that should teach me to proofread my comments... ;) )
Line 833 should ofcourse be:
out param name=wmode value=transparent if set_wmode_transparent
Add greater/less than, apostrophes, etc just as the other parameters on line 832-833
Regards Joachim
March 10th, 2008 at 06:15 AM Charlie,
I found a bug on the latest open_flash_chart.rb:
Line 406:
temp << 'so.addVariable("variable","true");'
should be:
temp << 'so.addVariable("variables","true");'
Line 125:
return "so.addVariable('#{function},#{values}');"
should be:
return "so.addVariable('#{function}','#{values}');"
With this two fixes, the js output_type works beautifully! Thank you so much, Charlie!
March 10th, 2008 at 06:32 PM @Joachim F. -
Good catch, committed it for you, thanks.
@Roni -
Wow, good eye :) I never use that part of the code, thanks for providing the fix.
March 21st, 2008 at 06:32 AM Great Work!
Where should I put the swobject.js file?
Do I need to include it in my layout?
(I ask because on a coworker's computer (ie 7) it forces you to click on the flash file before it functions.)
March 21st, 2008 at 10:30 AM Hi, thanks for the plugin, it's great. I'm using the pie chart but I've noticed that in your examples as well as on my page the labels for the chart as extremely small. I haven't been able to figure out how to resize them. Is this a bug or am I not setting something correctly?
Thanks
March 22nd, 2008 at 01:01 PM @chap-
swobject.js should go in the RAILS_ROOT/public/javascripts directory, then you must set_js_path() to /javascripts and also set the output_type to "js". Sorry I do not have an example of this, I will work on one. For now, read more on Teethgrinder's site.
@reza-
Thank you, I fixed my pie examples, see line 11 here - http://pullmonkey.com/projects/open_flash_chart/view_source_code/pie
Hope that helps.
March 27th, 2008 at 08:00 AM Hi,
Could you publish how the HTML object code looks like with the wmode setting because I am trying to do it straight in HTML but the background still shows.
Regards
March 27th, 2008 at 12:18 PM
@Mark A. -
I put the generated HTML up here - http://codes.graphs.skizmo.com/transparent
Hope that helps.
March 27th, 2008 at 02:45 PM I found a few bugs to allow the swfobject to work:
line 402: temp << ''
change to
temp << ''
line 504: temp << 'so.write(my_chart"' + @unique_id + '");'
change to
temp << 'so.write("' + @unique_id + '");'
This gets the div to work for the object.
Next, you need to include more member variables at methods for the graph type classes.
I would add:
@output_type to the Bar class (in initialize)
I would also add:
def set_output_type(type)
@output_type = type
end
These aren't inherited from the graph class, and they are needed in the "js" output types. I only looked at the Bar class, but I presume the same is needed for the other graph types to be compatible with the swfobject. Thanks, and great work!
March 27th, 2008 at 09:43 PM
@Brandon -
Thanks, I had a typo on line 504. my_chart" should have been "my_chart, where my_chart is on the inside of the quotes. Fixed it and updated the plugin.
As far as the output_type, I think you are right, I have not had time to look at it yet.
Thanks for your help.
March 27th, 2008 at 10:39 PM Hi Charlie,
I tried the HTML code in FireFox and IE 7 and the chart background was not transparent. Is there also a setting in the data file that enables this?
Thanks
March 28th, 2008 at 08:01 AM Charlie, I debated on removing "my_chart" or keeping it. I suppose if you keep it, one could manipulate the div...
You definitely need the output_type in the chart "type" classes (bar,line,etc), otherwise the "values", "links", "tool_tips_set", and the specific settings will never get applied through the swfobject. It is the difference between generating the so.addVariable text and not generating it.
If you want an example to post on your page on how to use the swfobject in rails, using this plugin, I would be more than happy to send you one.
March 28th, 2008 at 04:09 PM
@Brandon -
Thanks, I would love an example to post. Send it to charlie at pullmonkey dot com. I will build in the output_type code this weekend. Thanks again.
@Mark A. - I haven't had a tremendous amount of time, but I will look into it this weekend and hopefully have an example posted for you next week. I will keep you updated.
March 31st, 2008 at 07:55 PM I seem to be running into a problem when using "g.set_output_type('js')"
the output I'm getting is:
var so = new SWFObject("/r/open-flash-chart.swf", "ofc", "300", "150", "9", "#FFFFFF");
so.addVariable("variables","true");
so.addVariable('x_label_style','10,#9933CC,2');
so.addVariable('title','+,{font-size: 4px;}');
so.addVariable('y_label_style','9,#9933CC');
so.addVariable('y_min','0');
so.addVariable('x_axis_steps','1');
so.addVariable('bg_colour','0xf5f5f5');
so.addVariable('y_ticks','5,10,1');
so.addVariable('x_labels','OneTHing,Another,Blah,Apr,May,Jun,Jul,Aug,Sep,Oct');
so.addVariable('y_min','0');
so.addVariable('y_max','20');
&bar=50,#0066CC&
&values=3,4,3,6,5,5&
&bar_2=50,#9933CC&
&values_2=3,7,7,6,3,5&
so.write("my_charta0eabb91775534ebcdb3a54dda9d8e08");
which seems to be fine except for the:
&bar=50,#0066CC&
&values=3,4,3,6,5,5&
&bar_2=50,#9933CC&
&values_2=3,7,7,6,3,5&
parts.
I'm not sure if I'm missing something but I thought you might have an idea.
Thanks,
Sean
March 31st, 2008 at 09:05 PM
@Sean - no you are not missing anything, this is a bug :( I will take a look at this over the next week. I think it probably has to do with what Brandon is talking about.
March 31st, 2008 at 11:34 PM Charlie, thanks for the reply. Can't wait to see it all going. :)
April 3rd, 2008 at 07:05 AM Hi, I'd like to use graph with many data lines, but the example above is not working for me. When I tried pie chart, it worked great. The graph I want to use is here:
http://www.pullmonkey.com/projects/open_flash_chart/view_source_code/extra_tt
But the sample code isn't working for me. Although on the page is working, when I delete the "www" from url and go to:
http://pullmonkey.com/projects/open_flash_chart/view_source_code/extra_tt
the graph is not working(it doesn't render). This is what I'm getting. I'm confused. It's the same code. On one page is working but on the other (the one without www) is not. So I'm a little bit confused. Can anybody help me?
April 3rd, 2008 at 07:10 AM Correction:
The graph works on the url without "www" and doesn't wokr on the one with "www".
April 3rd, 2008 at 09:23 AM Hello, I'm having problems trying to create a full month data chart, 2 line_hollow, 31 x_labels, and It doesn't work, it stays loading T_T. The charts work perfectly with less data.
Here is my data output:
&x_grid_colour=#2D2D2D&
&tool_tip=%23val%23&
&x_label_style=10,#000000,2&
&y_min=0&
&x_axis_steps=1&
&x_axis_colour=#2D2D2D&
&y_axis_colour=#2D2D2D&
&y_grid_colour=#2D2D2D&
&bg_colour=#FFFFFF&
&y_ticks=5,10,10&
&line_hollow_2=2,#DF1010,Desubscripciones,11,5&
&line_hollow=2,#1C7703,Suscripciones,11,5&
&values=225,206,237,230,243,278,257,263,311,247,307,216,247,247,290,304,301,394,313,276,238,223,293,155,85,326,226,42&
&values_2=0,0,0,0,222,305,298,301,300,286,336,275,261,257,295,320,309,318,90,131,100,82,80,57,51,68,94,23&
&x_labels=20080201,20080202,20080203,20080204,20080205,20080206,20080207,20080208,20080209,20080210,20080211,20080212,20080213,20080214,20080215,20080216,20080217,20080218,20080219,20080220,20080221,20080222,20080223,20080224,20080225,20080226,20080227,20080228&
&y_min=0&
&y_max=394&
Any help would be very appreciated.
:D
April 3rd, 2008 at 10:20 AM Hello again. I finally fixed the problem. The problem was that although I reinstalled the plugin the file in /lib/open_flash_chart.rb stayed from the old version. So I simply copied it there form /vendor/plugins/open_flash.... and it worked :)
April 4th, 2008 at 10:08 AM
@banana - thanks for the notes, glad you got it working.
@Augusto - I am going to reproduce your problem and I will get back to you.
April 4th, 2008 at 11:55 PM You, my good sir, rock.
April 5th, 2008 at 05:12 PM
@Brandon - Thanks for the example. I posted it here.
Also, there was a bug in the output_type code where I had @output_type instead of just the local variable output_type. I committed the changes for this. So the "per class" set_output_type() method is unnecessary now :) - Thankfully.
@sean - your bug was related to the output_type fix. So get the latest plugin and you should be good, let me know.
@Mark A. - I am still working on the transparency code, have you had a chance to dig into it?
@Augusto - I had no problem getting your code to render, I posted the code that works for me on skizmo.com - here.
I think I got everyone's questions answered, if I missed you, please comment and I will be sure to answer.
Thanks.
April 6th, 2008 at 10:06 AM I admit it: I'm a rails newbie. I'm doing something wrong because I've yet been able to get a single chart working. Does anyone have a bare bones working project they can share so I can figure out what I am doing wrong? If so, please send it to bob.walsh@47hats.com. Thanks.
April 6th, 2008 at 11:35 PM pwd /Users/hwend/Development/GraphSample
ls -als
24 -rw-r--r-- 1 hwend hwend 8819 Apr 6 20:53 README
8 -rw-r--r-- 1 hwend hwend 307 Apr 6 20:53 Rakefile
0 drwxr-xr-x 6 hwend hwend 204 Apr 6 20:53 app
0 drwxr-xr-x 8 hwend hwend 272 Apr 6 20:53 config
0 drwxr-xr-x 3 hwend hwend 102 Apr 6 21:06 db
0 drwxr-xr-x 3 hwend hwend 102 Apr 6 20:53 doc
0 drwxr-xr-x 3 hwend hwend 102 Apr 6 20:53 lib
0 drwxr-xr-x 6 hwend hwend 204 Apr 6 20:53 log
0 drwxr-xr-x 17 hwend hwend 578 Apr 6 21:14 public
0 drwxr-xr-x 11 hwend hwend 374 Apr 6 20:53 script
0 drwxr-xr-x 8 hwend hwend 272 Apr 6 20:53 test
0 drwxr-xr-x 6 hwend hwend 204 Apr 6 20:53 tmp
0 drwxr-xr-x 4 hwend hwend 136 Apr 6 21:00 vendor
I appreciate any help what I am doing wrong here.
Thanks.
April 6th, 2008 at 11:45 PM Sorry, my comment got cut off. Here the first part...
I am a newbie and am trying to get the Spoon Sales sample to work.
I installed the plugin and copied the open-flash-chart.swf file into the /public directory and the swfobject.js file into my /public/javascripts directory.
My application root directory is /Users/hwend/Development/GraphSample
My controller:
class GraphController < ApplicationController
def view
@graph = open_flash_chart_object(500,250, '/public/open_flash_chart/one', true, '/public/')
end
def one
g = Graph.new
g.title("Spoon Sales", '{font-size: 26px;}')
g.set_data([0,0,33,16,9,11,30,48,47,49,16,49])
g.set_x_labels(%w(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec))
g.set_y_max(60)
g.set_y_label_steps(6)
render :text => g.render
end
end
My view:
<html>
<head>
<title>Graph Example</title>
</head>
<body>
<%= @graph %>
</body>
</html>
The errors in the browser I get are:
Resource interpreted as script but transferred with MIME type text/html.
http://localhost:3000/public/javascripts/swfobject.js
SyntaxError: Parse error
http://localhost:3000/public/javascripts/swfobject.js (line 1)
ReferenceError: Can't find variable: SWFObject
http://localhost:3000/graph/view (line 9)
The terminal output shows the error:
ActionController::RoutingError (No route matches "/public/javascripts/swfobject.js" with {:method=>:get}):
I would appreciate any help what I am doing wrong here.
Thanks.
April 7th, 2008 at 08:20 AM
@Bob Walsh - Horst (see comment above this one) has a pretty good example going, start with that, post errors if you can.
@Horst - you need to remove "public" from your code, "/" points to public, so "/public" in the url points to /public/public in your RAILS_ROOT. You want this:
@graph = open_flash_chart_object(500,250, '/graph/one', true, '/')
In my examples, "open_flash_chart" is the name of my controller and in your example it is "graph".
Hope that makes sense. Let me know.
April 7th, 2008 at 12:41 PM Charlie,
Thank you very much for your response. It is working like a charm now thanks to your help. I changed the call to @graph = open_flash_chart_object(500,250, '/graph/one', true, '/') and it did the trick.
Horst
April 8th, 2008 at 03:56 AM Hi, Is it possible that your svn repository is down?
script/plugin install http://svn.pullmonkey.com/open_flash_chart
Plugin not found: ["http://svn.pullmonkey.com/open_flash_chart"]
http://svn.pullmonkey.com/open_flash_chart returns a 404 error..
April 8th, 2008 at 04:00 AM never mind! apparently the correct url is http://svn.pullmonkey.com/plugins/trunk/open_flash_chart
Eager to try it out on 'big' datasets..
April 8th, 2008 at 08:02 AM
@Andrew - please let me know how it handles the "big" datasets. Also, did I post an incorrect plugin link somewhere?
April 8th, 2008 at 03:26 PM Charlie,
created a new project as per you/Horst.
with http://localhost:3000/graph/view
I get absolutely nothing...my html
is there, but no chart. Doing this on my Mac, in FF.
I'd be more than happy to send you the project... Arrrgh!
April 8th, 2008 at 04:09 PM
@Bob Walsh - Sure, send me the project- charlie at pullmonkey dot com
April 10th, 2008 at 07:50 AM
@Bob Walsh - got your files and responded to your email, just wanted to share the findings for anyone that is having trouble.
------
Bob,
Aha -- I see - you need to include the javascript file:
Here is the diff:
pullmonkey$ diff -u app/views/graph/view.html.erb.bob app/views/graph/view.html.erb
--- app/views/graph/view.html.erb.bob 2008-04-10 07:41:44.000000000 -0600
+++ app/views/graph/view.html.erb 2008-04-10 07:41:49.000000000 -0600
@@ -1,6 +1,7 @@
<html>
<head>
<title>Graph Example test</title>
+<%= javascript_include_tag :defaults, 'swfobject' %>
</head>
<body>
Where's the Chart?
So there are two ways that the graph can be produced.
1) javascript call to SWFObject
2) plain ol embeded object (if javascript is turned off --- or -- if you pass false to use_swfobject)
Two reasons for the javascript, 1) faster 2) IE.
In IE, the plain object will require the user to click the graph to activate.
Hope that gets you on your way,
Charlie
April 10th, 2008 at 09:17 AM Thanks Charlie - that did the trick.
April 14th, 2008 at 10:38 AM hello again, thanks for the help with the font size. i'm trying to push the percentage sign (%) to be displayed as part of the name of a slice of pie. I get weirdness. should i be using some special escape characters?
April 15th, 2008 at 06:51 AM @reza - I have not tried naming a slice with a percent sign, just labeling. It probably needs escaped, I will check into it today.
April 20th, 2008 at 11:13 PM Hi, thanks for this very useful plugin!
Two suggestions... use the plugin's install.rb to copy the needed files (swfobject.js, which you neglect to mention in your README, and open-flash-chart-swf)
Also, the ruby code could be more rubyish if:
* toString was named to_s (no big deal)
* the intializers call "yield if block_given?" and the subclassed initializers that call super, return self t the end. This allows the use of the magic pen pattern, like so: (also with snazzy RESTfulness)
April 21st, 2008 at 06:56 AM
@David -
Thanks for the pointers. The initial cut was just to get it from php to ruby, I have not done any refactoring or rubytization :(
As for the swfobject.js - I have now added it to the site instructions and the README and I will do as you suggest with the install.rb. Thanks!
April 22nd, 2008 at 11:52 PM As we see from http://www.pullmonkey.com/open-flash-chart/, open flash
chart don't support stacked bar. Is there any way to work around with
open flash chart or any other better idea about stacked bar using in
RoR?
Thanks.
May 1st, 2008 at 11:20 AM I want to add some chinese charactor at the y_lengend, but I failed to do that. Can you help me please thanks a lot.
May 1st, 2008 at 03:03 PM See this example - http://teethgrinder.co.uk/open-flash-chart/gallery-x-axis-2.php
The data that is produced needs to look like this:
http://teethgrinder.co.uk/open-flash-chart/gallery-data-18.php
May 2nd, 2008 at 01:06 PM Odd problem. The graph only shows up the first time I start the rails app. After that it never shows up again even in other browsers. I can load the page with the graph once and then it will not load again even when I start up another browser application and load the page.
Any thoughts. Current checkout as of the time of this message. Using either the current open flash chart distribution or the parts in the plugin.
May 15th, 2008 at 09:48 AM @Erik -
Had the same problem...turns out it is in the open_flash_chart.rb file. It is only including the swfobject.js source the first time it uses SWFObject. I moved the code doing the include...
out << '
... out of the conditional so it is always included, and that did the trick.
May 18th, 2008 at 08:43 AM howdy, i can hardly wait to try this plugin.
another thing i'm interested in, and was hoping to contact you via email but couldn't find, is skizmo.com/
how do you get skizmo to create subdomains, and how do you keep each site's 'look and feel' seperate, in simplecms?
can you email me to discuss?
May 20th, 2008 at 01:46 PM Thanks Chris!
I was really annoyed by restarting the server again and again. It also seems to work properly if you duplicate the "include"-Line into the else part where "open_flash_chart_seqno" is mentioned. What seems to be broken then is that the rest of the page doesnt render till you move your mouse out of the flash-area
May 27th, 2008 at 12:40 PM Are you considering moving to github? so we can have all plugins in git
June 2nd, 2008 at 08:31 PM I have a problem like Bob Walsh .The IE is blank ,but it has sourcefile.the sourcefile is following:
var so = new SWFObject("/open-flash-chart.swf", "chart_3","600","300", "9", "#FFFFFF");
so.addVariable("data", "%2Fgraph%2Fy_right");
so.addParam("allowScriptAccess", "sameDomain");
so.write("flashcontent_3");
<noscript>
<object>
width="600" height="300" id="ie_chart_3" align="middle">
<param />
<param />
<param />
<param />
<embed src="/open-flash-chart.swf?data=%2Fgraph%2Fy_right" height="300" width="600">
type="application/x-shockwave-flash" pluginpage="http://ww.macromedia.com/go/getflashplayer" id="chart_3"/>
</object>
</noscript>
my controller is that:
class GraphController < ApplicationController
def view
@graph = open_flash_chart_object(600,300, '/graph/y_right', true, '/')
end
def y_right
g = Graph.new
g.title( 'Users vs. Ram - 24h statistics', '{color: #7E97A6; font-size: 20; text-align: center}' )
g.set_bg_color('#FFFFFF')
g.set_data([289,198,143,126,98,96,124,164,213,238,256,263,265,294,291,289,306,341,353,353,402,419,404,366,309])
g.line_dot( 2, 4, '#818D9D', 'Max Users', 10 )
g.set_data([698,1101,1324,1396,1568,1571,1496,1349,1140,1045,966,926,906,754,766,757,672,510,431,436,227,533,566,744,1004])
g.line_hollow( 2, 4, '#164166', 'Free Ram', 10 )
g.attach_to_y_right_axis(2)
g.set_y_max(600)
g.set_y_right_max(1700)
g.set_x_axis_color('#818D9D', '#F0F0F0' )
g.set_y_axis_color( '#818D9D', '#ADB5C7' )
g.y_right_axis_color('#164166' )
g.set_x_legend( 'My IRC Server', 12, '#164166' )
g.set_y_legend( 'Max Users', 12, '#164166' )
g.set_y_legend_right( 'Free Ram (MB)' ,12 , '#164166' )
tmp = []
(0..25).to_a.each do |x|
tmp << "#{x}:00"
end
g.set_x_labels(tmp)
g.set_x_label_style(10, '#164166', 0, 3, '#818D9D' )
g.set_y_label_steps(5)
render :text => g.render
end
end
Thanks
June 2nd, 2008 at 09:13 PM
@percy - Did you include the javascript file (swfobject.js)?
Doesn't look like it, add the line:
<%= javascript_include_tag 'swfobject' %>
to your view html or your layout.
June 3rd, 2008 at 04:50 AM I was wondering how easy it might be to add links to a scatter graph. I need each point on the graph to link to a comment somewhere else on the page. Has anyone managed something like that? I can't quite tell from the lib whether it's possible to add a link to any of the graph objects or just the line and bar.
I tried adding one to the tooltip, but any code apart from '
' seems to get rendered inline.
Any hacking help much appreciated!
June 5th, 2008 at 12:31 PM any chance you have the transparent background of the graph as an option we can enable anywhere in there? trying to set the bg_colors to something like 'transparent' and no go on anything I can think of, is it possible? thanks,
Nick
June 6th, 2008 at 07:38 AM Hi, wonderful site! I'm using a few of your graphs and everyone here is impressed. Just wanted to let you know theres a bug on your pie charts - the tooltips are displaying the wrong values. that's all, keep up the good work!
June 6th, 2008 at 03:55 PM
@nick - transparency ... well, it is supposed to be supported but nothing yet.
@Nick (same as nick I bet) - Good catch, it is happening on Teeth Grinder's (the guy who did the swf work) site - http://teethgrinder.co.uk/open-flash-chart/gallery-pie.php I will see what bug reports there are for that, and if none will add one. Thanks.
June 6th, 2008 at 04:06 PM
@Dorian - Hacking the plugin won't help, it all comes down to the swf that teeth grinder put together. This functionality would have to start at his end. You just gotta ask him :)
June 12th, 2008 at 12:14 PM Good work!
I ran into a problem. The plugin works perfectly to produce the chart, however, when I click on the refresh button, the chart does not show up. IE complains that the SWFObject is not defined. By comparing the source, it seems when I click refresh, the page does not have the following line:
src="/javascripts/swfobject.js">
I notice this is caused by the following code:
if !$open_flash_chart_seqno
$open_flash_chart_seqno = 1
out << '
else
$open_flash_chart_seqno += 1
obj_id += "_#{$open_flash_chart_seqno}"
div_name += "_#{$open_flash_chart_seqno}"
end
So when $open_flash_chart_seqno > 1, the page does not link in the javascript url.
Is there an easy way to fix this? Or I am doing something wrong?
Thanks,
Lieting
June 13th, 2008 at 07:25 AM
@Lieting - You can fix this by including that javascript file in your layout by hand .. that is what I do. I would expect the ofc seqno to reset itself upon refreshing, but in your case I am not sure what is going on.
June 22nd, 2008 at 03:07 PM Step by step tutorial for beginners! (from scratch)
@@@@@@@@@@@@@@
Download open flash chart package
Navigate to an environment that supports ruby-on-rails
@@@@@@@@@@@@@@
start a project from scratch
rails practice
cd practice
copy the ruby-ofc-library-pullmonkey into practice/vendor/plugins dir and rename the library as open_flash_chart
Alternatively run: script/plugin install http://svn.pullmonkey.com/plugins/trunk/open_flash_chart/
Move the open_flash_chart.swf file into your practice/public directory
Move the swfobject.js file into your practice/public/javascripts directory
rake db:create
ruby script/generate migration Trial
rake db:migrate
@@@@@@@@@@@@@@
Edit trial_controller in practice/app/controllers directory
class TrialController < ApplicationController
def view
@graph = open_flash_chart_object(500,250, '/trial/bar_chart', false, '/')
end
def bar_chart
bar = BarOutline.new(50, '#9933CC', '#8010A0')
bar.key("Page VIEWS", 10)
10.times do |t|
bar.data << rand(7) + 3
end
g = Graph.new
g.title("BAR CHART", "{font-size: 15px;}")
g.data_sets << bar
g.set_x_labels(%w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct))
g.set_x_label_style(10, '#9933CC', 0,2)
g.set_x_axis_steps(2)
g.set_y_max(10)
g.set_y_label_steps(4)
g.set_y_legend("OPENF LADF", 12, "#736AFF")
render :text => g.render
end
end
@@@@@@@@@@@@@@
create index.html file in practice/app/views/trial directory
copy and paste the following onto the index.html file
<object>
<embed src="/open-flash-chart.swf?data=%2Ftrial%2Fbar_chart" height="250" width="500">
</object>
@@@@@@@@@@@@@@
Note: Make sure you have adobe flash player installed in your machine
@@@@@@@@@@@@@@
watch the magic:
ruby script/server
Go to http://localhost:3000/trial/index
Hope this helped my fellow newbies.
July 4th, 2008 at 08:46 AM I have the same problem as others, with blank results.
Controller name is: test_graphs
I've installed the plugin, moved the .js to javascript lib and .swf to public.
I have the javascript + :defaults in my layout. So this means I've added a layout RHTML file to match my view.
Here's my controller:
class TestGraphsController < ApplicationController
def view
@graph = open_flash_chart_object(500,250, '/test_graphs/one', true, '/')
end
def one
g = Graph.new
g.title("Spoon Sales", '{font-size: 26px;}')
g.set_data([0,0,33,16,9,11,30,48,47,49,16,49])
g.set_x_labels(%w(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec))
g.set_y_max(60)
g.set_y_label_steps(6)
render :text => g.render
end
end
Here's the view (index.rhtml) under test_graphs:
<html>
<head>
<title>Graph Example</title>
</head>
<body>
<%= @graph %>
</body>
</html>
Results:
Blank screen...what am i missing?
July 7th, 2008 at 01:01 AM It seems like the problem for those seeing blank pages is caused by the code in view.
It also does not work for me with <%= @graph %>
Replace this with and it works fine.
<object>
<embed src="/open-flash-chart.swf?data=%2Ftrial%2Fbar_chart" height="250" width="500">
</object>
If anyone can tell me why the original code did not work, kindly let us know. I have Fedora 8 and Firefox.
July 19th, 2008 at 11:45 AM Hi, great work! I am curious. Will 1.9.7 ruby library work in OFC 2, or is there another library for that? Sorry if this is answered elswhere, I tried to google and did not find what I was looking for.
Thanks, and keep up the great work!
D
July 21st, 2008 at 09:29 AM @ Charlie:
Big thanks for the plugin, I use it in all my projects now.
Q1: Do you have plans to support OFC2? Looks to me that the only diff on your parts is to just pass JSON instead of the old format.
Q2: Would you consider moving the project to GitHub so that we could branch and help out a bit?
July 21st, 2008 at 08:49 PM @Karl, Darin -
Yes, plan on supporting OFC2. I will move it to github asap.
July 23rd, 2008 at 09:58 AM Fantastic job, Charlie.
July 24th, 2008 at 09:03 PM Hi! Found/Fixed a bug!
You've got support for styling the 'right y axis', but there is one line of code missing to allow it to work. You need to add one line to the property hash built on line 409 of the lib/open_flash_chart.rb file:
"y2_label_style" => [@y2_label_style],
Otherwise, great work!
July 24th, 2008 at 09:07 PM shoot, the line i pasted in there was wrong. It should be:
"y2_label_style" => [@y_label_style_right],
The use/translation of y2 and y_right and y_*_right was making my head spin. :)
July 25th, 2008 at 11:05 AM
@benjamin - Thanks for the bug fix. Just so you know, version two is out and on github.
version II instruction and example - http://pullmonkey.com/2008/7/23/open-flash-chart-ii-plugin-for-ruby-on-rails-ofc2
Another version II example - http://pullmonkey.com/2008/7/25/using-a-database-to-populate-an-open-flash-chart-graph
The Github repository - http://github.com/pullmonkey/open_flash_chart/tree/master
July 27th, 2008 at 10:25 AM Hi, I don't speak english very well. I do not understand any things and need help to handle this plugin. Might someone help?
July 27th, 2008 at 11:18 AM
@Cecci - start with this example: http://pullmonkey.com/2008/7/23/open-flash-chart-ii-plugin-for-ruby-on-rails-ofc2
Then move on to this example: http://pullmonkey.com/2008/7/25/using-a-database-to-populate-an-open-flash-chart-graph
July 29th, 2008 at 02:13 AM hello,
I'm first sorry for my bag english,
I'm a french customer, and i want use your graphics plugin for make a plugin for redmine.
i have follow all the instructions for the installation of the plugin but i have a problem on the display.
On my view, we can see the frame of flash but into in the place of my graph i have the path of my graph like : /migrate/y_right
the path of the object in the controlleur work for a plugin ( /vendor/plugin/migrate/app/controllers/migrate_controller.rb )
my controlleur :
My controller:
class MigrateController < ApplicationController
def view
@graph = open_flash_chart_object(600,300, '/migrate/y_right', true, '/')
end
def one
g = Graph.new
g.title("Spoon Sales", '{font-size: 26px;}')
g.set_data([0,0,33,16,9,11,30,48,47,49,16,49])
g.set_x_labels(%w(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec))
g.set_y_max(60)
g.set_y_label_steps(6)
render :text => g.render
end
end
My view:
<html>
<head>
<title>Graph Example</title>
</head>
<body>
<%= @graph %>
</body>
</html>
if the option object at true, my firebug say :
SWFObject is not defined
[Break on this error] var so = new SWFObject("/open-flash-char..."chart_24","600","300", "9", "#FFFFFF");
And if it's at false i have the display described above.
I hope my explication is not to had to understand.
And i hope you can help me.
Thx for your help
July 29th, 2008 at 02:23 AM Erf for the copied/colled
in my controllor :
def one
g = Graph.new
g.title("Spoon Sales", '{font-size: 26px;}')
g.set_data([0,0,33,16,9,11,30,48,47,49,16,49])
g.set_x_labels(%w(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec))
g.set_y_max(60)
g.set_y_label_steps(6)
render :text => g.render
end
is not def one but really def y_right
i'm sorry
July 29th, 2008 at 08:00 AM
@Victor - You need to include the javascript file (swfobject.js) in your view.html.erb or in your layout's head, that is why SWFObject is not defined .... Also, I recommend you look at using the new version (version 2 from my github) of open flash chart, here are some instructions - http://pullmonkey.com/2008/7/23/open-flash-chart-ii-plugin-for-ruby-on-rails-ofc2
More examples - http://pullmonkey.com/projects/open_flash_chart2/
July 29th, 2008 at 09:25 AM @charlie - i have include the javascript file in the layout on redmine (
and the problem are always here
My view are in *.rhtml ... it's perhaps a probleme...
also i will install your new version on this plugin.
I'm dispointed if i can't using it because i fing your plugin are very pleasant and ergonomic
October 6th, 2008 at 05:59 PM I saw the recommendation to Victor in the version 2 thread about using the older version after encountering error parsing the JSON. I'm working with rails 1.2 and I am not able to access the svn.pullmonkey.com repository, the domain name does not resolve. Please let me know if there is still a hosted copy, if not, could you add it to the git project as legacy code? Otherwise, is there any intention to support rails 1.2?
October 7th, 2008 at 06:04 PM I have the same problem with a blank screen sometime on IE only. Sometime it shows the chart, while other time it does. Refresh sometime brings out the chart, but not always. Any pointer will be appreciated.
October 7th, 2008 at 08:57 PM
@Noah - I just switched from dreamhost to slicehost and that subdomain went away in dns, so had to get that all set up. So anyway, the svn is back.
@pdx3d - regular or javascript does not work in IE? Next, do any of the pullmonkey.com graphs show up in your IE?
October 7th, 2008 at 11:19 PM Charlie, thanks for your prompt response.
Yes, regular javascript works. In fact, OFC2 works sometime, but not always. I am running on windows under ROR with webbrick(and tried mongrel as well). FireFox and Chrome all works fine, but not IE. Use the same IE, I can see this site fine. When the chart is not shown, I can still see the html source showing the tags for all the elements the same as when it works. Just no chart is actually showing...
I forgot to mention: I really like what I see when it works.
October 8th, 2008 at 08:01 AM
@pdx3d - Ok, look in the rails logs and see if the swfobject is making the ajax request to the action you setup. Also, what version of rails are you using? What version of IE? I need to reproduce the problem to fix it :) so the more details the better. Thanks for your time and patience.
October 8th, 2008 at 10:15 AM Charlie,
I was not using the ajax version, but rather :
@graph= open_flash_chart_object(320,240,"/ofc2/graph_code")
under IE7: 7.0.6001.18000.
I just swtiched to the ajax version moments ago. It works beautifully! Thanks again.