Class: GoogleChart::BarChart
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
-
#alignment ⇒ Object
Returns the value of attribute alignment.
-
#stacked ⇒ Object
Returns the value of attribute stacked.
Attributes inherited from Base
#chart_size, #chart_title, #chart_type, #data_encoding, #params, #show_labels, #show_legend
Instance Method Summary collapse
-
#initialize(chart_size = '300x200', chart_title = nil, alignment = :vertical, stacked = false) ⇒ BarChart
constructor
Specify the *
chart_sizein WIDTHxHEIGHT format *chart_titleas a string *alignmentas either:verticalor:horizontal*stackedshould betrueif you want the bars to be stacked, false otherwise. - #process_data ⇒ Object
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_sizein WIDTHxHEIGHT format -
chart_titleas a string -
alignmentas either:verticalor:horizontal -
stackedshould betrueif 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
#alignment ⇒ Object
Returns the value of attribute alignment.
9 10 11 |
# File 'lib/google_chart/bar_chart.rb', line 9 def alignment @alignment end |
#stacked ⇒ Object
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_data ⇒ Object
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 |