Hi All, Is there a simple way to produce charts and graphs in rails? Like a bar graph or some such? I searched in the wiki to no avail. Many thanks in advance. CHEERS> SAM
Sam Joseph wrote:> Hi All, > > Is there a simple way to produce charts and graphs in rails? Like a bar > graph or some such? I searched in the wiki to no avail. > > Many thanks in advance. >Ron Sweeney and Brian Barto did some experimenting with bringin the Ruby/GD framework up to speed for ruby 1.8 to as a proof of concept. The original posting is here: http://article.gmane.org/gmane.comp.lang.ruby.rails/21716/match=ruby+gd They''ve been talking about possibly ressurrecting Ruby/GD, but to what avail I dont know at this time. Zach
Hi Sam, First off, Hi! I''m new to the list etc. To make some simple graphs i used the SVG::Graph library + RMagick, you can get at SVG::Graph from: http://www.germane-software.com/software/SVG/SVG::Graph/ It produces a number of simple graph types, it''s not all that configurable - but it does the job. As it spits out SVG, you have no guarantee that it''ll work on the clients browser, so I rasterized the graphs to PNG format using RMagick, works a treat. A sample bar graph can be viewed at: http://philprice.net/kiosklog/graphmaster/yearly_overview And a pie chart: http://philprice.net/kiosklog/graphmaster/upload_speed_distribution If i had a blog I would now link to an article I would have written on how to piece this all together, but I don''t have a blog. So really there are two things to remeber if you want to go this route. Make sure you set :compression => false, for the Graphing objects, otherwise RMagick won''t like reading the data. And here is the method to turn svg data into a nice png... def push_graph if params[:type] == "SVG" send_data @graph.burn, :type => "image/xml+svg", :disposition => "inline" else image = Magick::Image.from_blob(@graph.burn)[0] image.format = "PNG" send_data image.to_blob, :type => image.mime_type, :disposition => "inline" end end Cheers Phil On 22/10/05, zdennis <zdennis-aRAREQmnvsAAvxtiuMwx3w@public.gmane.org> wrote:> > Sam Joseph wrote: > > Hi All, > > > > Is there a simple way to produce charts and graphs in rails? Like a bar > > graph or some such? I searched in the wiki to no avail. > > > > Many thanks in advance. > > > > Ron Sweeney and Brian Barto did some experimenting with bringin the > Ruby/GD framework up to speed for ruby 1.8 to as a proof of concept. > > The original posting is here: > http://article.gmane.org/gmane.comp.lang.ruby.rails/21716/match=ruby+gd > > They''ve been talking about possibly ressurrecting Ruby/GD, but to what > avail I dont know at this time. > > Zach > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Look ma: http://nubyonrails.topfunky.com/articles/2005/07/28/sparklines-graph-library-for-ruby Greetz, Martin Sam Joseph wrote:> Hi All, > > Is there a simple way to produce charts and graphs in rails? Like a bar > graph or some such? I searched in the wiki to no avail. > > Many thanks in advance. > > CHEERS> SAM
sparklines is pretty nice, here is a shady alternative... I posted this ahile ago Sam: After our last Ruby Meetup, Brian and I were able to get Ruby/GD working with rails to give is a colorful graph based on values from Active Record. http://www.modelm.org/modelms/rubygdtest <---Here is our proof of concept We have three things we would like to get some advice on, then I will outline how we hacked it into submission. 1. What are others using as a graph utility with either Ruby or Rails? 2. Is there a more elegant way than the way below? 3. Is Ruby/GD dead? Here is the gory details to get this going on FreeBSD 5. something or other... install gd from ports install ruby-gd from ports install gdchart (0.0.9! not 0.0.5) from sourceforge and build it (http://sourceforge.jp/projects/ruby-gdchart/) no port anymore for gdchart, it died after 4.X. we had to hax0r the location of some header files, gd.h and font*.h.. gds.h in the following files: gdc.h, gifencode.c... we built it until the errors went away... after that, we wrote a ruby script (pie_sample.rb) that looked like this: #!/usr/local/bin/ruby # Ruby/GD test with Active Record # Ron Sweeney and Brian Barto ( http://www.gr-ruby.org/ ) # Is Ruby/GD dead ? require ''GDChart'' require ''rubygems'' require ''active_record'' ActiveRecord::Base.establish_connection(:adapter => "mysql", :host => "localhost ", :database => "modelm", :username => "flounder", :password => "***********") class Modelm < ActiveRecord::Base end print "Content-Type: image/png" print "\n\n" #setup the chart gdc = GDChartPie.new gdc.title = "Model M Keyboards around the world (ruby/gd test)..." gdc.EdgeColor = 0x000000 gdc.Color = [ 0xFF3322, 0xFF9933, 0xFFEE33, 0x33FFFF ] gdc.BGColor = 0x000000 gdc.explode = [ 40, 20, 10, 30] gdc.angle_3d = 90 gdc.depth_3d = 40 gdc.perspective = 5 gdc.image_type = GDChart::PNG #Gets us some values via Active Record us = Modelm.count "location = ''United States''" canadia = Modelm.count "location = ''Canada''" brazil = Modelm.count "location = ''Brazil''" philli = Modelm.count "location = ''Philippines''" #Put the data on the chart data = [us, canadia, brazil, philli] label = ["United States", "Canada", "Brazil", "Philippines"] gdc.out_graph(600, 600, $stdout, GDChartPie::PIE3D, data.length, label, data) Then, we referenced it from within rails as a script that rendered an image, a PNG in this instance like so... <img src="http://www.modelm.org/cgi-bin/pie_sample.rb"> Works like a champ, however its as elegant as perl''s CPAN, know what I mean? On 10/23/05, Martin Honermeyer <maze-/iAHrS655dmM7HLlUNEGLrNAH6kLmebB@public.gmane.org> wrote:> > Look ma: > > http://nubyonrails.topfunky.com/articles/2005/07/28/sparklines-graph-library-for-ruby > > > Greetz, > Martin > > Sam Joseph wrote: > > > Hi All, > > > > Is there a simple way to produce charts and graphs in rails? Like a bar > > graph or some such? I searched in the wiki to no avail. > > > > Many thanks in advance. > > > > CHEERS> SAM > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- "Force Feedback Computing Since 1984" http://www.modelm.org http://www.clubpacswestmi.net/sweeney/ http://www.clubpacswestmi.net _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi Phil, Thanks for the tips - I tried, but I think my novice ruby/rails status is holding me back I think. I downloaded SVG::Graph, but there are no install instructions so I just put it in the following directory: D:\ruby\lib\ruby\1.8 and ran the following command: D:\ruby\lib\ruby\1.8\svg_graph_0.6.1>ruby install.rb then I created a controller like this: require ''SVG/Graph/BarHorizontal'' class GraphController < ApplicationController def push_graph fields = %w(Jan Feb Mar) data_sales_02 = [12, 45, 21] graph = SVG::Graph::BarHorizontal.new({ :height => 500, :width => 300, :fields => fields, :compression => false }) graph.add_data({ :data => data_sales_02, :title => ''Sales 2002'', }) if params[:type] == "SVG" send_data graph.burn, :type => "image/xml+svg", :disposition => "inline" else image = Magick::Image.from_blob(graph.burn)[0] image.format = "PNG" send_data image.to_blob, :type => image.mime_type, :disposition => "inline" end end end and added the following to environments.rb require ''svg_graph'' but I get the following error: UnableToOpenFile `'': No such file or directory: /app/controllers/graph_controller.rb:24:in `from_blob'' /app/controllers/graph_controller.rb:24:in `push_graph''.. Any help greatly appreciated. CHEERS> SAM Phil Price wrote:> Hi Sam, > > First off, Hi! I''m new to the list etc. > > To make some simple graphs i used the SVG::Graph library + RMagick, > you can get at SVG::Graph from: > http://www.germane-software.com/software/SVG/SVG::Graph/ > > It produces a number of simple graph types, it''s not all that > configurable - but it does the job. As it spits out SVG, you have no > guarantee that it''ll work on the clients browser, so I rasterized the > graphs to PNG format using RMagick, works a treat. > > A sample bar graph can be viewed at: > http://philprice.net/kiosklog/graphmaster/yearly_overview > > And a pie chart: > http://philprice.net/kiosklog/graphmaster/upload_speed_distribution > > If i had a blog I would now link to an article I would have written on > how to piece this all together, but I don''t have a blog. So really > there are two things to remeber if you want to go this route. Make > sure you set :compression => false, for the Graphing objects, > otherwise RMagick won''t like reading the data. And here is the method > to turn svg data into a nice png... > > def push_graph > if params[:type] == "SVG" > send_data @graph.burn, :type => > "image/xml+svg", :disposition => "inline" > else > image = Magick::Image.from_blob(@graph.burn)[0] > image.format = "PNG" > send_data image.to_blob, :type => > image.mime_type, :disposition => "inline" > end > end > > Cheers > > Phil > > On 22/10/05, *zdennis* <zdennis-aRAREQmnvsAAvxtiuMwx3w@public.gmane.org <mailto:zdennis-aRAREQmnvsAAvxtiuMwx3w@public.gmane.org>> > wrote: > > Sam Joseph wrote: > > Hi All, > > > > Is there a simple way to produce charts and graphs in rails? > Like a bar > > graph or some such? I searched in the wiki to no avail. > > > > Many thanks in advance. > > > > Ron Sweeney and Brian Barto did some experimenting with bringin the > Ruby/GD framework up to speed for ruby 1.8 to as a proof of concept. > > The original posting is here: > http://article.gmane.org/gmane.comp.lang.ruby.rails/21716/match=ruby+gd > > They''ve been talking about possibly ressurrecting Ruby/GD, but to what > avail I dont know at this time. > > Zach > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org <mailto:Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org> > http://lists.rubyonrails.org/mailman/listinfo/rails > > >------------------------------------------------------------------------ > >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > >
Hi Sam,> Is there a simple way to produce charts and graphs in rails? Like a bar > graph or some such? I searched in the wiki to no avail.I would recommend the use of either Ploticus or Imlib2. Imlib2 is very fast drawing library and comes from the enlightment-team. The ruby bindings are here: http://pablotron.org/software/imlib2-ruby Ploticus is good if you want to create diagrams and don''t want to write your own drawing-tool. http://wiki.rubyonrails.com/rails/pages/RubyPloticus The ruby-bindings are currently offline, but should be back soon (I am not the author, ask Michael Neumann mneumann(.at.)ntecs.de). regards, Helmut