Class: GoogleChart::BarChart

Inherits:
Base
  • Object
show all
Defined in:
lib/google_chart/bar_chart.rb

Overview

Generates a Bar Chart. You can specify the alignment(horizontal or vertical) and whether you want the bars to be grouped or stacked

Examples

bc = GoogleChart::BarChart.new('800x200', "Bar Chart", :vertical, false)
bc.data "Trend 1", [5,4,3,1,3,5], '0000ff'

Constant Summary

Constants inherited from Base

GoogleChart::Base::BASE_URL, GoogleChart::Base::COMPLEX_ENCODING_ALPHABET, GoogleChart::Base::SIMPLE_ENCODING

Instance Attribute Summary collapse

Attributes inherited from Base

#chart_size, #chart_title, #chart_type, #data_encoding, #params, #show_labels, #show_legend

Instance Method Summary collapse

Methods inherited from Base

#axis, #data, #fill, #grid, #to_url

Constructor Details

#initialize(chart_size = '300x200', chart_title = nil, alignment = :vertical, stacked = false) ⇒ BarChart

Specify the

  • chart_size in WIDTHxHEIGHT format

  • chart_title as a string

  • alignment as either :vertical or :horizontal

  • stacked should be true if you want the bars to be stacked, false otherwise



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

def initialize(chart_size='300x200', chart_title=nil, alignment=:vertical, stacked=false)
    super(chart_size, chart_title)
    @alignment = alignment
    @stacked = stacked
    set_chart_type
    self.show_labels = false
    self.show_legend = true
end

Instance Attribute Details

#alignmentObject

Returns the value of attribute alignment.



9
10
11
# File 'lib/google_chart/bar_chart.rb', line 9

def alignment
  @alignment
end

#stackedObject

Returns the value of attribute stacked.



9
10
11
# File 'lib/google_chart/bar_chart.rb', line 9

def stacked
  @stacked
end

Instance Method Details

#process_dataObject



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

def process_data
    if @data.size > 1
        max_value = @data.flatten.max
          join_encoded_data(@data.collect { |series|
            encode_data(series, max_value)
          })
    else
        encode_data(@data.flatten)
    end
end