Class: Seer::ColumnChart

Inherits:
Object
  • Object
show all
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

Attributes included from Chart

#chart_element, #colors

Class Method Summary collapse

Instance Method Summary collapse

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_colorObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def axis_background_color
  @axis_background_color
end

#axis_colorObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def axis_color
  @axis_color
end

#axis_font_sizeObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def axis_font_size
  @axis_font_size
end

#background_colorObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def background_color
  @background_color
end

#border_colorObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def border_color
  @border_color
end

#dataObject

Graph data



48
49
50
# File 'lib/seer/column_chart.rb', line 48

def data
  @data
end

#data_methodObject

Graph data



48
49
50
# File 'lib/seer/column_chart.rb', line 48

def data_method
  @data_method
end

#data_tableObject

:nodoc:



48
49
50
# File 'lib/seer/column_chart.rb', line 48

def data_table
  @data_table
end

#enable_tooltipObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def enable_tooltip
  @enable_tooltip
end

#focus_border_colorObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def focus_border_color
  @focus_border_color
end

#heightObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def height
  @height
end

#is_3_dObject

:nodoc:



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def is_3_d
  @is_3_d
end

#is_stackedObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def is_stacked
  @is_stacked
end

#label_methodObject

Graph data



48
49
50
# File 'lib/seer/column_chart.rb', line 48

def label_method
  @label_method
end

#legendObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def legend
  @legend
end

#legend_background_colorObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def legend_background_color
  @legend_background_color
end

#legend_font_sizeObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def legend_font_size
  @legend_font_size
end

#legend_text_colorObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def legend_text_color
  @legend_text_color
end

#log_scaleObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def log_scale
  @log_scale
end

#maxObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def max
  @max
end

#minObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def min
  @min
end

#reverse_axisObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def reverse_axis
  @reverse_axis
end

#show_categoriesObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def show_categories
  @show_categories
end

#titleObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def title
  @title
end

#title_colorObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def title_color
  @title_color
end

#title_font_sizeObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def title_font_size
  @title_font_size
end

#title_xObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def title_x
  @title_x
end

#title_yObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def title_y
  @title_y
end

#tooltip_font_sizeObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def tooltip_font_size
  @tooltip_font_size
end

#tooltip_heightObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def tooltip_height
  @tooltip_height
end

#tooltip_widthObject

Chart options accessors



45
46
47
# File 'lib/seer/column_chart.rb', line 45

def tooltip_width
  @tooltip_width
end

#widthObject

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_optionsObject

:nodoc:



83
84
85
# File 'lib/seer/column_chart.rb', line 83

def nonstring_options #: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_optionsObject

:nodoc:



87
88
89
# File 'lib/seer/column_chart.rb', line 87

def string_options #: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_jsObject

: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 = {};
#{options}
        var container = document.getElementById('#{self.chart_element}');
        var chart = new google.visualization.ColumnChart(container);
        chart.draw(data, options);
      }
    </script>
  }
end