Forum: Ruby on Rails Gruff

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Johnny B (Guest)
on 2006-04-22 14:14
I have installed Gruff and am trying to get an example to work i found
at
http://tomcopeland.blogs.com/juniordeveloper/2006/....

I have the following code in the controller:
# Send a graph to the browser
  def crumpetchartaction
    days = 5
    g = Gruff::Line.new(500)
    g.title = "Crumpets over the past #{days} days"
    g.theme_keynote
    crumpets_to_date = []
    labels = {}
    days.downto(0) do |day|
      date_stamp = Time.now - (60*60*24*day)
      date_sql_string = date_stamp.strftime("%Y-%m-%d")
      crumpets_to_date << Crumpets.count("created_on <
'#{date_sql_string}'").to_i
      labels[days-day] = date_stamp.strftime("%b %d") if day % 3 == 0
    end

    g.data("Crumpets Sold", crumpets_to_date)
    g.labels = labels
    send_data(g.to_blob, 	:disposition => 'inline', 	:type =>
'image/png', 	:filename => "crumpets_over_time.png")

  end


How do i display this graph in the view???
<img src="/blog/crumpetchartaction"/>
Tom C. (Guest)
on 2006-04-23 00:26
(Received via mailing list)
On Sat, 2006-04-22 at 12:14 +0200, Johnny B wrote:
> I have installed Gruff and am trying to get an example to work i found
> at
> http://tomcopeland.blogs.com/juniordeveloper/2006/....

Cool, glad that's proving useful!

> How do i display this graph in the view???
> <img src="/blog/crumpetchartaction"/>

Precisely.  At least, that works for me.  And you can always check it in
the browser manually by just going to:

http://yourhost/blog/crumpetchartaction

and seeing if the graph shows up.

Yours,

Tom
This topic is locked and can not be replied to.