Class: Chart::GroupedBar

Inherits:
Base
  • Object
show all
Defined in:
lib/chart/grouped_bar.rb

Instance Attribute Summary

Attributes inherited from Base

#colors, #data, #height, #label_format, #labels, #legend, #line_width, #margins, #multicolor, #object, #plot_area, #plot_top_margin, #position, #radius, #style, #symbols, #width

Instance Method Summary collapse

Methods inherited from Base

#helper, #initialize, #write

Constructor Details

This class inherits a constructor from Chart::Base

Instance Method Details

#generateObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/chart/grouped_bar.rb', line 8

def generate
  # set the plot area
  @object.setPlotArea(@margins[0], @margins[1], @plot_area[0], @plot_area[1], 0xe9e9e9, 0xf5f5f5)
  
  # set the legend position
  @object.addLegend(@margins[0], 0, false, "normal", 8).setBackground(ChartDirector::Transparent)
  
  # set the top margin
  @object.yAxis.setTopMargin(@plot_top_margin)
  
  # set the labels
  @object.xAxis.setLabels(@labels)
  
  # create the layer
  layer = @object.addBarLayer2(ChartDirector::Side, 0)
  
  # add data to layer
  @data.each_with_index do |data, index|
    layer.addDataSet(data, @colors[index], legend[index])
  end
end

#instantiateObject



3
4
5
6
# File 'lib/chart/grouped_bar.rb', line 3

def instantiate
  # instantiate a new chart
  @object = ChartDirector::XYChart.new(@width, @height) if @width && @height
end