Class: Axlsx::BarSeries

Inherits:
Series
  • Object
show all
Defined in:
lib/axlsx/drawing/bar_series.rb

Overview

Note:

The recommended way to manage series is to use Chart#add_series

A BarSeries defines the title, data and labels for bar charts

Instance Attribute Summary collapse

Attributes inherited from Series

#chart, #title

Instance Method Summary collapse

Methods inherited from Series

#index, #order, #order=

Constructor Details

#initialize(chart, options = {}) ⇒ BarSeries

Creates a new series

Parameters:

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

    a customizable set of options

Options Hash (options):

  • data (Array, SimpleTypedList)
  • labels (Array, SimpleTypedList)
  • title (String)
  • shape (String)
  • colors (String)

    an array of colors to use when rendering each data point



33
34
35
36
37
38
39
# File 'lib/axlsx/drawing/bar_series.rb', line 33

def initialize(chart, options={})
  @shape = :box
  @colors = []
  super(chart, options)
  self.labels = AxDataSource.new({:data => options[:labels]}) unless options[:labels].nil?
  self.data = NumDataSource.new(options) unless options[:data].nil?
end

Instance Attribute Details

#colorsObject

An array of rgb colors to apply to your bar chart.



24
25
26
# File 'lib/axlsx/drawing/bar_series.rb', line 24

def colors
  @colors
end

#dataNumDataSource

The data for this series.

Returns:



12
13
14
# File 'lib/axlsx/drawing/bar_series.rb', line 12

def data
  @data
end

#labelsArray, SimpleTypedList

The labels for this series.

Returns:

  • (Array, SimpleTypedList)


16
17
18
# File 'lib/axlsx/drawing/bar_series.rb', line 16

def labels
  @labels
end

#shapeSymbol

The shabe of the bars or columns must be one of [:percentStacked, :clustered, :standard, :stacked]

Returns:

  • (Symbol)


21
22
23
# File 'lib/axlsx/drawing/bar_series.rb', line 21

def shape
  @shape
end

Instance Method Details

#to_xml_string(str = '') ⇒ String

Serializes the object

Parameters:

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

Returns:

  • (String)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/axlsx/drawing/bar_series.rb', line 54

def to_xml_string(str = '')
  super(str) do |str_inner|

    colors.each_with_index do |c, index|
      str_inner << '<c:dPt>'
      str_inner << '<c:idx val="' << index.to_s << '"/>'
      str_inner << '<c:spPr><a:solidFill>'
      str_inner << '<a:srgbClr val="' << c << '"/>'
      str_inner << '</a:solidFill></c:spPr></c:dPt>'
    end

    @labels.to_xml_string(str_inner) unless @labels.nil?
    @data.to_xml_string(str_inner) unless @data.nil?
    # this is actually only required for shapes other than box 
    str_inner << '<c:shape val="' << shape.to_s << '"></c:shape>'
  end
end