Class: Seer::Gauge
Overview
USAGE
In your controller:
@data = Widgets.all # Must be an array, and must respond
# to the data method specified below (in this example, 'quantity')
In your view:
<div id="chart"></div>
<%= Seer::visualize(
@data,
:as => :gauge,
:in_element => 'chart',
:series => {:series_label => 'name', :data_method => 'quantity'},
:chart_options => {
:green_from => 0,
:green_to => 50,
:height => 300,
:max => 100,
:min => 0,
:minor_ticks => 5,
:red_from => 76,
:red_to => 100,
:width => 600,
:yellow_from => 51,
:yellow_to => 75
}
)
-%>
For details on the chart options, see the Google API docs at code.google.com/apis/visualization/documentation/gallery/gauge.html
Constant Summary
Constants included from Chart
Chart::DEFAULT_COLORS, Chart::DEFAULT_HEIGHT, Chart::DEFAULT_LEGEND_LOCATION, Chart::DEFAULT_WIDTH
Instance Attribute Summary collapse
-
#data ⇒ Object
Graph data.
-
#data_method ⇒ Object
Graph data.
-
#data_table ⇒ Object
:nodoc:.
-
#green_from ⇒ Object
Chart options accessors.
-
#green_to ⇒ Object
Chart options accessors.
-
#height ⇒ Object
Chart options accessors.
-
#label_method ⇒ Object
Graph data.
-
#major_ticks ⇒ Object
Chart options accessors.
-
#max ⇒ Object
Chart options accessors.
-
#min ⇒ Object
Chart options accessors.
-
#minor_ticks ⇒ Object
Chart options accessors.
-
#red_from ⇒ Object
Chart options accessors.
-
#red_to ⇒ Object
Chart options accessors.
-
#width ⇒ Object
Chart options accessors.
-
#yellow_from ⇒ Object
Chart options accessors.
-
#yellow_to ⇒ Object
Chart options accessors.
Attributes included from Chart
Class Method Summary collapse
-
.render(data, args) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Gauge
constructor
:nodoc:.
-
#is_3_d ⇒ Object
:nodoc:.
-
#nonstring_options ⇒ Object
:nodoc:.
-
#string_options ⇒ Object
:nodoc:.
-
#to_js ⇒ Object
:nodoc:.
Methods included from Chart
#data_columns, #formatted_colors, #in_element=, #options
Constructor Details
#initialize(args = {}) ⇒ Gauge
:nodoc:
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/seer/gauge.rb', line 48 def initialize(args={}) #:nodoc: # Standard options args.each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method) } # Chart options args[:chart_options].each{ |method, arg| self.send("#{method}=",arg) if self.respond_to?(method) } # Handle defaults @height ||= args[:chart_options][:height] || DEFAULT_HEIGHT @width ||= args[:chart_options][:width] || DEFAULT_WIDTH @data_table = [] end |
Instance Attribute Details
#data ⇒ Object
Graph data
46 47 48 |
# File 'lib/seer/gauge.rb', line 46 def data @data end |
#data_method ⇒ Object
Graph data
46 47 48 |
# File 'lib/seer/gauge.rb', line 46 def data_method @data_method end |
#data_table ⇒ Object
:nodoc:
46 47 48 |
# File 'lib/seer/gauge.rb', line 46 def data_table @data_table end |
#green_from ⇒ Object
Chart options accessors
43 44 45 |
# File 'lib/seer/gauge.rb', line 43 def green_from @green_from end |
#green_to ⇒ Object
Chart options accessors
43 44 45 |
# File 'lib/seer/gauge.rb', line 43 def green_to @green_to end |
#height ⇒ Object
Chart options accessors
43 44 45 |
# File 'lib/seer/gauge.rb', line 43 def height @height end |
#label_method ⇒ Object
Graph data
46 47 48 |
# File 'lib/seer/gauge.rb', line 46 def label_method @label_method end |
#major_ticks ⇒ Object
Chart options accessors
43 44 45 |
# File 'lib/seer/gauge.rb', line 43 def major_ticks @major_ticks end |
#max ⇒ Object
Chart options accessors
43 44 45 |
# File 'lib/seer/gauge.rb', line 43 def max @max end |
#min ⇒ Object
Chart options accessors
43 44 45 |
# File 'lib/seer/gauge.rb', line 43 def min @min end |
#minor_ticks ⇒ Object
Chart options accessors
43 44 45 |
# File 'lib/seer/gauge.rb', line 43 def minor_ticks @minor_ticks end |
#red_from ⇒ Object
Chart options accessors
43 44 45 |
# File 'lib/seer/gauge.rb', line 43 def red_from @red_from end |
#red_to ⇒ Object
Chart options accessors
43 44 45 |
# File 'lib/seer/gauge.rb', line 43 def red_to @red_to end |
#width ⇒ Object
Chart options accessors
43 44 45 |
# File 'lib/seer/gauge.rb', line 43 def width @width end |
#yellow_from ⇒ Object
Chart options accessors
43 44 45 |
# File 'lib/seer/gauge.rb', line 43 def yellow_from @yellow_from end |
#yellow_to ⇒ Object
Chart options accessors
43 44 45 |
# File 'lib/seer/gauge.rb', line 43 def yellow_to @yellow_to end |
Class Method Details
.render(data, args) ⇒ Object
:nodoc:
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/seer/gauge.rb', line 106 def self.render(data, args) #:nodoc: graph = Seer::Gauge.new( :data => data, :label_method => args[:series][:series_label], :data_method => args[:series][:data_method], :chart_options => args[:chart_options], :chart_element => args[:in_element] || 'chart' ) graph.to_js end |
Instance Method Details
#is_3_d ⇒ Object
:nodoc:
74 75 76 |
# File 'lib/seer/gauge.rb', line 74 def is_3_d #:nodoc: @is_3_d.blank? ? false : @is_3_d end |
#nonstring_options ⇒ Object
:nodoc:
78 79 80 |
# File 'lib/seer/gauge.rb', line 78 def #:nodoc: [:green_from, :green_to, :height, :major_ticks, :max, :min, :minor_ticks, :red_from, :red_to, :width, :yellow_from, :yellow_to] end |
#string_options ⇒ Object
:nodoc:
82 83 84 |
# File 'lib/seer/gauge.rb', line 82 def #:nodoc: [] end |
#to_js ⇒ Object
:nodoc:
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/seer/gauge.rb', line 86 def to_js #:nodoc: %{ <script type="text/javascript"> google.load('visualization', '1', {'packages':['gauge']}); google.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.DataTable(); #{data_columns} #{data_table.join} var options = {}; #{} var container = document.getElementById('#{self.chart_element}'); var chart = new google.visualization.Gauge(container); chart.draw(data, options); } </script> } end |