Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems' #1
- require 'activerecord'
- # Begin ActiveRecord configuration
- ActiveRecord::Base.establish_connection( #2
- :adapter => "mysql",
- :host => "localhost",
- :database => "paper",
- :username => "root",
- :password => "" #,
- #:socket => "/var/run/mysqld/mysqld.sock" #/var/lib/gems/1.8/gems/activerecord-2.1.0/lib/active_record/vendor/mysql.rb
- )
- # Begin ActiveRecord classes
- class Product < ActiveRecord::Base #3
- has_many :purchases
- end
- class Purchase < ActiveRecord::Base
- belongs_to :store
- end
- class Store < ActiveRecord::Base
- end
- # Begin logic
- myproducts = Product.find(:all) #4
- #require 'pp'
- #pp myproducts
- require 'scruffy'
- graph = Scruffy::Graph.new #1
- graph.title = "Comparison of Product Sales"
- stores = Store.find(:all, :select=>"id, location")
- myproducts.each do |product| #2
- counts = stores.collect do |store|
- Purchase.count "id", :store_id=>store.id, :product_id=>product.id
- end
- graph.add :line, product.name, counts #3
- end
- graph.point_markers =
- Store.find(:all).map! {|store| store.location}
- graph.render :as => 'PNG', :to => 'productsales.png',
- :width => 720,
- :theme => Scruffy::Themes::Keynote.new
Add Comment
Please, Sign In to add comment