Class: Axlsx::BarChart

Inherits:
Chart
  • Object
show all
Defined in:
lib/axlsx/drawing/bar_chart.rb

Overview

The BarChart is a two dimentional barchart that you can add to your worksheet.

Instance Attribute Summary

Attributes inherited from Chart

#bg_color, #display_blanks_as, #graphic_frame, #legend_position, #series, #series_type, #show_legend, #style, #title, #vary_colors, #view_3D

Instance Method Summary collapse

Methods inherited from Chart

#add_series, #d_lbls, #end_at, #from, #index, #pn, #relationship, #start_at, #title_size=, #to

Methods included from OptionsParser

#parse_options

Constructor Details

#initialize(frame, options = {}) ⇒ BarChart

Creates a new bar chart object

Parameters:

  • frame (GraphicFrame)

    The workbook that owns this chart.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • title (Cell, String)
  • show_legend (Boolean)
  • bar_dir (Symbol)
  • grouping (Symbol)
  • gap_width (String)
  • shape (Symbol)

See Also:



69
70
71
72
73
74
75
# File 'lib/axlsx/drawing/bar_chart.rb', line 69

def initialize(frame, options={})
  @vary_colors = true
  @gap_width, @overlap, @shape = nil, nil, nil
  super(frame, options)
  @series_type = BarSeries
  @d_lbls = nil
end

Instance Method Details

#axesAxes

A hash of axes used by this chart. Bar charts have a value and category axes specified via axes[:val_axes] and axes[:cat_axis]

Returns:



134
135
136
# File 'lib/axlsx/drawing/bar_chart.rb', line 134

def axes
 @axes ||= Axes.new(:cat_axis => CatAxis, :val_axis => ValAxis)
end

#bar_dirSymbol Also known as: barDir

The direction of the bars in the chart must be one of [:bar, :col]

Returns:

  • (Symbol)


28
29
30
# File 'lib/axlsx/drawing/bar_chart.rb', line 28

def bar_dir
  @bar_dir ||= :bar
end

#bar_dir=(v) ⇒ Object Also known as: barDir=

The direction of the bars in the chart must be one of [:bar, :col]



79
80
81
82
# File 'lib/axlsx/drawing/bar_chart.rb', line 79

def bar_dir=(v)
  RestrictionValidator.validate "BarChart.bar_dir", [:bar, :col], v
  @bar_dir = v
end

#cat_axisCatAxis Also known as: catAxis

the category axis

Returns:



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

def cat_axis
  axes[:cat_axis]
end

#gap_widthInteger Also known as: gapWidth

space between bar or column clusters, as a percentage of the bar or column width.

Returns:

  • (Integer)


35
36
37
# File 'lib/axlsx/drawing/bar_chart.rb', line 35

def gap_width
  @gap_width ||= 150
end

#gap_width=(v) ⇒ Object Also known as: gapWidth=

space between bar or column clusters, as a percentage of the bar or column width.



93
94
95
96
# File 'lib/axlsx/drawing/bar_chart.rb', line 93

def gap_width=(v)
  RangeValidator.validate "BarChart.gap_width", 0, 500, v
  @gap_width=(v)
end

#groupingSymbol

grouping for a column, line, or area chart. must be one of [:percentStacked, :clustered, :standard, :stacked]

Returns:

  • (Symbol)


43
44
45
# File 'lib/axlsx/drawing/bar_chart.rb', line 43

def grouping
  @grouping ||= :clustered
end

#grouping=(v) ⇒ Object

grouping for a column, line, or area chart. must be one of [:percentStacked, :clustered, :standard, :stacked]



87
88
89
90
# File 'lib/axlsx/drawing/bar_chart.rb', line 87

def grouping=(v)
  RestrictionValidator.validate "BarChart.grouping", [:percentStacked, :clustered, :standard, :stacked], v
  @grouping = v
end

#overlapInteger

Overlap between series

Returns:

  • (Integer)


49
50
51
# File 'lib/axlsx/drawing/bar_chart.rb', line 49

def overlap
  @overlap ||= 0
end

#overlap=(v) ⇒ Object



99
100
101
102
# File 'lib/axlsx/drawing/bar_chart.rb', line 99

def overlap=(v)
  RangeValidator.validate "BarChart.overlap", -100, 100, v
  @overlap=(v)
end

#shapeSymbol

The shape of the bars or columns must be one of [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax]

Returns:

  • (Symbol)


56
57
58
# File 'lib/axlsx/drawing/bar_chart.rb', line 56

def shape
  @shape ||= :box
end

#shape=(v) ⇒ Object

The shape of the bars or columns must be one of [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax]



106
107
108
109
# File 'lib/axlsx/drawing/bar_chart.rb', line 106

def shape=(v)
  RestrictionValidator.validate "BarChart.shape", [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax], v
  @shape = v
end

#to_xml_string(str = '') ⇒ String

Serializes the object

Parameters:

  • str (String) (defaults to: '')

Returns:

  • (String)


114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/axlsx/drawing/bar_chart.rb', line 114

def to_xml_string(str = '')
  super(str) do
    str << '<c:barChart>'
    str << ('<c:barDir val="' << bar_dir.to_s << '"/>')
    str << ('<c:grouping val="' << grouping.to_s << '"/>')
    str << ('<c:varyColors val="' << vary_colors.to_s << '"/>')
    @series.each { |ser| ser.to_xml_string(str) }
    @d_lbls.to_xml_string(str) if @d_lbls
    str << ('<c:overlap val="' << @overlap.to_s << '"/>') unless @overlap.nil?
    str << ('<c:gapWidth val="' << @gap_width.to_s << '"/>') unless @gap_width.nil?
    str << ('<c:shape val="' << @shape.to_s << '"/>') unless @shape.nil?
    axes.to_xml_string(str, :ids => true)
    str << '</c:barChart>'
    axes.to_xml_string(str)
  end
end

#val_axisValAxis Also known as: valAxis

the value axis

Returns:



20
21
22
# File 'lib/axlsx/drawing/bar_chart.rb', line 20

def val_axis
  axes[:val_axis]
end