Class: Seer::AreaChart
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')
@series = @data.map{|w| w.} # An array of arrays
In your view:
<div id="chart"></div>
<%= Seer::visualize(
@data,
:as => :area_chart,
:in_element => 'chart',
:series => {
:series_label => 'name',
:data_label => 'date',
:data_method => 'quantity',
:data_series => @series
},
:chart_options => {
:height => 300,
:width => 300,
:axis_font_size => 11,
:colors => ['#7e7587','#990000','#009900'],
:title => "Widget Quantities",
:point_size => 5
}
)
-%>
For details on the chart options, see the Google API docs at code.google.com/apis/visualization/documentation/gallery/areachart.html
Constant Summary
Constants included from Chart
Chart::DEFAULT_COLORS, Chart::DEFAULT_HEIGHT, Chart::DEFAULT_LEGEND_LOCATION, Chart::DEFAULT_WIDTH
Instance Attribute Summary collapse
-
#axis_background_color ⇒ Object
Graph options.
-
#axis_color ⇒ Object
Graph options.
-
#axis_font_size ⇒ Object
Graph options.
-
#background_color ⇒ Object
Graph options.
-
#border_color ⇒ Object
Graph options.
-
#data ⇒ Object
Graph data.
-
#data_label ⇒ Object
Graph data.
-
#data_method ⇒ Object
Graph data.
-
#data_series ⇒ Object
Graph data.
-
#data_table ⇒ Object
:nodoc:.
-
#enable_tooltip ⇒ Object
Graph options.
-
#focus_border_color ⇒ Object
Graph options.
-
#height ⇒ Object
Graph options.
-
#is_stacked ⇒ Object
Graph options.
-
#legend ⇒ Object
Graph options.
-
#legend_background_color ⇒ Object
Graph options.
-
#legend_font_size ⇒ Object
Graph options.
-
#legend_text_color ⇒ Object
Graph options.
-
#line_size ⇒ Object
Graph options.
-
#log_scale ⇒ Object
Graph options.
-
#max ⇒ Object
Graph options.
-
#min ⇒ Object
Graph options.
-
#number ⇒ Object
Graph options.
-
#point_size ⇒ Object
Graph options.
-
#reverse_axis ⇒ Object
Graph options.
-
#series_label ⇒ Object
Graph data.
-
#show_categories ⇒ Object
Graph options.
-
#title ⇒ Object
Graph options.
-
#title_color ⇒ Object
Graph options.
-
#title_font_size ⇒ Object
Graph options.
-
#title_x ⇒ Object
Graph options.
-
#title_y ⇒ Object
Graph options.
-
#tooltip_font_size ⇒ Object
Graph options.
-
#tooltip_height ⇒ Object
Graph options.
-
#tooltip_width ⇒ Object
Graph options.
-
#width ⇒ Object
Graph options.
Attributes included from Chart
Class Method Summary collapse
-
.render(data, args) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#data_columns ⇒ Object
:nodoc:.
- #data_rows ⇒ Object
-
#initialize(args = {}) ⇒ AreaChart
constructor
:nodoc:.
-
#nonstring_options ⇒ Object
:nodoc:.
-
#string_options ⇒ Object
:nodoc:.
-
#to_js ⇒ Object
:nodoc:.
Methods included from Chart
#formatted_colors, #in_element=, #options
Constructor Details
#initialize(args = {}) ⇒ AreaChart
:nodoc:
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/seer/area_chart.rb', line 50 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 @colors ||= args[:chart_options][:colors] || DEFAULT_COLORS @legend ||= args[:chart_options][:legend] || DEFAULT_LEGEND_LOCATION @height ||= args[:chart_options][:height] || DEFAULT_HEIGHT @width ||= args[:chart_options][:width] || DEFAULT_WIDTH @data_table = [] end |
Instance Attribute Details
#axis_background_color ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def axis_background_color @axis_background_color end |
#axis_color ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def axis_color @axis_color end |
#axis_font_size ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def axis_font_size @axis_font_size end |
#background_color ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def background_color @background_color end |
#border_color ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def border_color @border_color end |
#data ⇒ Object
Graph data
48 49 50 |
# File 'lib/seer/area_chart.rb', line 48 def data @data end |
#data_label ⇒ Object
Graph data
48 49 50 |
# File 'lib/seer/area_chart.rb', line 48 def data_label @data_label end |
#data_method ⇒ Object
Graph data
48 49 50 |
# File 'lib/seer/area_chart.rb', line 48 def data_method @data_method end |
#data_series ⇒ Object
Graph data
48 49 50 |
# File 'lib/seer/area_chart.rb', line 48 def data_series @data_series end |
#data_table ⇒ Object
:nodoc:
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def data_table @data_table end |
#enable_tooltip ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def enable_tooltip @enable_tooltip end |
#focus_border_color ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def focus_border_color @focus_border_color end |
#height ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def height @height end |
#is_stacked ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def is_stacked @is_stacked end |
#legend ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def legend @legend end |
#legend_background_color ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def legend_background_color @legend_background_color end |
#legend_font_size ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def legend_font_size @legend_font_size end |
#legend_text_color ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def legend_text_color @legend_text_color end |
#line_size ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def line_size @line_size end |
#log_scale ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def log_scale @log_scale end |
#max ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def max @max end |
#min ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def min @min end |
#number ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def number @number end |
#point_size ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def point_size @point_size end |
#reverse_axis ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def reverse_axis @reverse_axis end |
#series_label ⇒ Object
Graph data
48 49 50 |
# File 'lib/seer/area_chart.rb', line 48 def series_label @series_label end |
#show_categories ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def show_categories @show_categories end |
#title ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def title @title end |
#title_color ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def title_color @title_color end |
#title_font_size ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def title_font_size @title_font_size end |
#title_x ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def title_x @title_x end |
#title_y ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def title_y @title_y end |
#tooltip_font_size ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def tooltip_font_size @tooltip_font_size end |
#tooltip_height ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def tooltip_height @tooltip_height end |
#tooltip_width ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def tooltip_width @tooltip_width end |
#width ⇒ Object
Graph options
45 46 47 |
# File 'lib/seer/area_chart.rb', line 45 def width @width end |
Class Method Details
.render(data, args) ⇒ Object
:nodoc:
124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/seer/area_chart.rb', line 124 def self.render(data, args) #:nodoc: graph = Seer::AreaChart.new( :data => data, :series_label => args[:series][:series_label], :data_series => args[:series][:data_series], :data_label => args[:series][:data_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
#data_columns ⇒ Object
:nodoc:
68 69 70 71 72 73 74 75 |
# File 'lib/seer/area_chart.rb', line 68 def data_columns #:nodoc: _data_columns = " data.addRows(#{data_rows.size});\r" _data_columns << " data.addColumn('string', 'Date');\r" data.each do |datum| _data_columns << " data.addColumn('number', '#{datum.send(series_label)}');\r" end _data_columns end |
#data_rows ⇒ Object
90 91 92 93 94 |
# File 'lib/seer/area_chart.rb', line 90 def data_rows data_series.inject([]) do |rows, element| rows |= element.map { |e| e.send(data_label) } end end |
#nonstring_options ⇒ Object
:nodoc:
96 97 98 |
# File 'lib/seer/area_chart.rb', line 96 def #:nodoc: [ :axis_font_size, :colors, :enable_tooltip, :height, :is_stacked, :legend_font_size, :line_size, :log_scale, :max, :min, :point_size, :reverse_axis, :show_categories, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width] end |
#string_options ⇒ Object
:nodoc:
100 101 102 |
# File 'lib/seer/area_chart.rb', line 100 def #:nodoc: [ :axis_color, :axis_background_color, :background_color, :border_color, :focus_border_color, :legend, :legend_background_color, :legend_text_color, :title, :title_x, :title_y, :title_color ] end |
#to_js ⇒ Object
:nodoc:
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/seer/area_chart.rb', line 104 def to_js #:nodoc: %{ <script type="text/javascript"> google.load('visualization', '1', {'packages':['areachart']}); google.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.DataTable(); #{data_columns} #{data_table.join("\r")} var options = {}; #{} var container = document.getElementById('#{self.chart_element}'); var chart = new google.visualization.AreaChart(container); chart.draw(data, options); } </script> } end |