Class: GoogleChart::BarChart

Inherits:
Base
  • Object
show all
Includes:
Axis, Color, DataArray, Fills, Grid, Legend, Markers
Defined in:
lib/google_chart/bar_chart.rb

Constant Summary

ORIENTATIONS =
[:horizontal, :vertical]
GROUPINGS =
[:grouped, :stacked]

Constants included from Markers

Markers::ORIENTATION, Markers::PRIORITY, Markers::SHAPES

Constants included from Axis

Axis::ALIGNMENT_MAPPING, Axis::AXIS_TYPE_MAPPING

Constants included from Fills

Fills::FILL_KINDS, Fills::FILL_TYPES, Fills::FILL_TYPES_SOLID, Fills::FILL_TYPE_CODES

Instance Attribute Summary (collapse)

Attributes inherited from Base

#encoding, #height, #title, #title_color, #title_font_size, #width

Instance Method Summary (collapse)

Methods included from Markers

#range_marker, #shape_marker

Methods included from Grid

#grid

Methods included from Axis

#axis

Methods included from Fills

#fill

Methods included from DataArray

#data, included

Methods included from Legend

included

Methods inherited from Base

inherited, #query_params, #size, #size=, #to_url

Constructor Details

- (BarChart) initialize(options = {})

:nodoc:



18
19
20
21
22
23
24
# File 'lib/google_chart/bar_chart.rb', line 18

def initialize(options={}) #:nodoc:
  @orientation = :vertical
  @grouping    = :grouped
  set_chart_type
  @show_legend = true
  super(options)
end

Instance Attribute Details

- (Object) bar_spacing

Returns the value of attribute bar_spacing



13
14
15
# File 'lib/google_chart/bar_chart.rb', line 13

def bar_spacing
  @bar_spacing
end

- (Object) bar_width

Returns the value of attribute bar_width



13
14
15
# File 'lib/google_chart/bar_chart.rb', line 13

def bar_width
  @bar_width
end

- (Object) group_spacing

Returns the value of attribute group_spacing



13
14
15
# File 'lib/google_chart/bar_chart.rb', line 13

def group_spacing
  @group_spacing
end

- (Object) grouping

Returns the value of attribute grouping



13
14
15
# File 'lib/google_chart/bar_chart.rb', line 13

def grouping
  @grouping
end

- (Object) orientation

Returns the value of attribute orientation



13
14
15
# File 'lib/google_chart/bar_chart.rb', line 13

def orientation
  @orientation
end

Instance Method Details

- (Object) add_bar_width_and_spacing



67
68
69
70
71
72
# File 'lib/google_chart/bar_chart.rb', line 67

def add_bar_width_and_spacing
  str = "#{@bar_width}" if @bar_width
  str+= ",#{@bar_spacing}" if @bar_spacing
  str+= ",#{@group_spacing}" if @group_spacing
  @params[:chbh] = str if str
end

- (Object) encode_data



74
75
76
77
78
79
80
81
# File 'lib/google_chart/bar_chart.rb', line 74

def encode_data
  # override encode_data to set custom max value for stacked charts (unless max is already set)
  if grouping == :stacked and not self.max
    # set max value to the max value of sums
    self.max = @data.inject(Array.new(@data.first.size,0)) { |sum_series, series|  sum_series.zip(series).collect { |d| d.first + d.last } }.max
  end
  super
end

- (Object) set_chart_type



39
40
41
42
43
44
45
46
47
# File 'lib/google_chart/bar_chart.rb', line 39

def set_chart_type
  @chart_type = (
                 if    @orientation == :horizontal and @grouping == :grouped then "bhg"
                 elsif @orientation == :horizontal and @grouping == :stacked then "bhs"
                 elsif @orientation == :vertical   and @grouping == :grouped then "bvg"
                 elsif @orientation == :vertical   and @grouping == :stacked then "bvs"
                 end
                )
end