mlins (owner)

Revisions

gist: 1841 Download_button fork
public
Public Clone URL: git://gist.github.com/1841.git
Embed All Files: show embed
graph.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class GraphsController < ApplicationController
  
  def top
    @graph = open_flash_chart_object(1200, 500, '/graphs/bar_chart')
  end
  
  def bar_chart
    top = Customer.find(:all, :select => 'sum(CMS.ORD_TOTAL) AS total, CUST.COMPANY', :group => 'CMS.CUSTNUM, CUST.COMPANY', :joins => [:orders], :limit => 10, :order => 'total DESC')
 
    bar = BarOutline.new(50, '#9933CC', '#8010A0')
    bar.key('Sales', 10)
    
    labels = Array.new
    
    top.each do |t|
      bar.data << (t.total)
      labels << t.COMPANY.gsub('&', ' and ').chomp
    end
    
    g = Graph.new
    g.title("Top Dealers", "{font-size:20px}")
    g.data_sets << bar
    
    g.set_x_labels(labels)
    g.set_x_label_style(8, '#9933CC', 0,1)
    g.set_x_axis_steps(1)
    
    g.set_y_max(1500000)
    g.set_y_label_steps(10)
    
    g.set_y_legend("Dollars", 12, "#736AFF")
    render :text => g.render
    
  end
  
end