Class: Seer::ColumnChart
- Inherits:
-
Object
- Object
- Seer::ColumnChart
- Includes:
- Chart
- Defined in:
- lib/seer/column_chart.rb
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(
@widgets,
:as => :column_chart,
:in_element => 'chart',
:series => {:series_label => 'name', :data_method => 'quantity'},
:chart_options => {
:height => 300,
:width => 300,
:is_3_d => true,
:legend => 'none',
:colors => "[{color:'#990000', darker:'#660000'}]",
:title => "Widget Quantities",
:title_x => 'Widgets',
:title_y => 'Quantities'
}
)
-%>
Colors are treated differently for 2d and 3d graphs. If you set is_3_d to false, set the graph color like this:
:colors => "#990000"
For details on the chart options, see the Google API docs at code.google.com/apis/visualization/documentation/gallery/columnchart.html
Constant Summary
Constants included from Chart
Seer::Chart::DEFAULT_COLORS, Seer::Chart::DEFAULT_HEIGHT, Seer::Chart::DEFAULT_LEGEND_LOCATION, Seer::Chart::DEFAULT_WIDTH
Instance Attribute Summary collapse
-
#axis_background_color ⇒ Object
Chart options accessors.
-
#axis_color ⇒ Object
Chart options accessors.
-
#axis_font_size ⇒ Object
Chart options accessors.
-
#background_color ⇒ Object
Chart options accessors.
-
#border_color ⇒ Object
Chart options accessors.
-
#data ⇒ Object
Graph data.
-
#data_method ⇒ Object
Graph data.
-
#data_table ⇒ Object
:nodoc:.
-
#enable_tooltip ⇒ Object
Chart options accessors.
-
#focus_border_color ⇒ Object
Chart options accessors.
-
#height ⇒ Object
Chart options accessors.
-
#is_3_d ⇒ Object
:nodoc:.
-
#is_stacked ⇒ Object
Chart options accessors.
-
#label_method ⇒ Object
Graph data.
-
#legend ⇒ Object
Chart options accessors.
-
#legend_background_color ⇒ Object
Chart options accessors.
-
#legend_font_size ⇒ Object
Chart options accessors.
-
#legend_text_color ⇒ Object
Chart options accessors.
-
#log_scale ⇒ Object
Chart options accessors.
-
#max ⇒ Object
Chart options accessors.
-
#min ⇒ Object
Chart options accessors.
-
#reverse_axis ⇒ Object
Chart options accessors.
-
#show_categories ⇒ Object
Chart options accessors.
-
#title ⇒ Object
Chart options accessors.
-
#title_color ⇒ Object
Chart options accessors.
-
#title_font_size ⇒ Object
Chart options accessors.
-
#title_x ⇒ Object
Chart options accessors.
-
#title_y ⇒ Object
Chart options accessors.
-
#tooltip_font_size ⇒ Object
Chart options accessors.
-
#tooltip_height ⇒ Object
Chart options accessors.
-
#tooltip_width ⇒ Object
Chart options accessors.
-
#width ⇒ Object
Chart options accessors.
Attributes included from Chart
Class Method Summary collapse
-
.render(data, args) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ ColumnChart
constructor
: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 = {}) ⇒ ColumnChart
:nodoc:
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/seer/column_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 @is_3_d ||= args[:chart_options][:is_3_d] @data_table = [] end |
Instance Attribute Details
#axis_background_color ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def axis_background_color @axis_background_color end |
#axis_color ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def axis_color @axis_color end |
#axis_font_size ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def axis_font_size @axis_font_size end |
#background_color ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def background_color @background_color end |
#border_color ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def border_color @border_color end |
#data ⇒ Object
Graph data
48 49 50 |
# File 'lib/seer/column_chart.rb', line 48 def data @data end |
#data_method ⇒ Object
Graph data
48 49 50 |
# File 'lib/seer/column_chart.rb', line 48 def data_method @data_method end |
#data_table ⇒ Object
:nodoc:
48 49 50 |
# File 'lib/seer/column_chart.rb', line 48 def data_table @data_table end |
#enable_tooltip ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def enable_tooltip @enable_tooltip end |
#focus_border_color ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def focus_border_color @focus_border_color end |
#height ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def height @height end |
#is_3_d ⇒ Object
:nodoc:
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def is_3_d @is_3_d end |
#is_stacked ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def is_stacked @is_stacked end |
#label_method ⇒ Object
Graph data
48 49 50 |
# File 'lib/seer/column_chart.rb', line 48 def label_method @label_method end |
#legend ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def legend @legend end |
#legend_background_color ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def legend_background_color @legend_background_color end |
#legend_font_size ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def legend_font_size @legend_font_size end |
#legend_text_color ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def legend_text_color @legend_text_color end |
#log_scale ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def log_scale @log_scale end |
#max ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def max @max end |
#min ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def min @min end |
#reverse_axis ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def reverse_axis @reverse_axis end |
#show_categories ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def show_categories @show_categories end |
#title ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def title @title end |
#title_color ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def title_color @title_color end |
#title_font_size ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def title_font_size @title_font_size end |
#title_x ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def title_x @title_x end |
#title_y ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def title_y @title_y end |
#tooltip_font_size ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def tooltip_font_size @tooltip_font_size end |
#tooltip_height ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def tooltip_height @tooltip_height end |
#tooltip_width ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def tooltip_width @tooltip_width end |
#width ⇒ Object
Chart options accessors
45 46 47 |
# File 'lib/seer/column_chart.rb', line 45 def width @width end |
Class Method Details
.render(data, args) ⇒ Object
:nodoc:
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/seer/column_chart.rb', line 111 def self.render(data, args) #:nodoc: graph = Seer::ColumnChart.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
#nonstring_options ⇒ Object
:nodoc:
83 84 85 |
# File 'lib/seer/column_chart.rb', line 83 def #:nodoc: [:axis_font_size, :colors, :enable_tooltip, :height, :is_3_d, :is_stacked, :legend_font_size, :log_scale, :max, :min, :reverse_axis, :show_categories, :title_font_size, :tooltip_font_size, :tooltip_width, :width] end |
#string_options ⇒ Object
:nodoc:
87 88 89 |
# File 'lib/seer/column_chart.rb', line 87 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:
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/seer/column_chart.rb', line 91 def to_js #:nodoc: %{ <script type="text/javascript"> google.load('visualization', '1', {'packages':['columnchart']}); 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.ColumnChart(container); chart.draw(data, options); } </script> } end |