Skip to content

Instantly share code, notes, and snippets.

@andion
Created June 9, 2009 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andion/126540 to your computer and use it in GitHub Desktop.
Save andion/126540 to your computer and use it in GitHub Desktop.
def self.posts_and_comments_per_month_graph(number_of_months = 3)
require 'gruff'
g = Gruff::Line.new #Define a New Graph
g.title = "Recent posts and comments per month" #Title for the Graph
current = Time.current
posts_data = []
comments_data = []
labels_data = {}
number_of_months.downto(0) do |t|
month = current.months_ago(t)
posts_data << Post.in_one_month(month).count
comments_data << Comment.in_one_month(month).count
labels_data[(number_of_months - t)] = month.strftime('%B')
end
g.data("Posts", posts_data)
g.data("Comments", comments_data)
g.labels = labels_data
return g.to_blob
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment