Class: Axlsx::Series

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

Overview

Note:

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

A Series defines the common series attributes and is the super class for all concrete series types.

See Also:

Direct Known Subclasses

BarSeries, LineSeries, PieSeries

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Series) initialize(chart, options = {})

Creates a new series

Parameters:

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

    a customizable set of options

Options Hash (options):

  • order (Integer)
  • title (String)


28
29
30
31
32
33
34
# File 'lib/axlsx/drawing/series.rb', line 28

def initialize(chart, options={})
  self.chart = chart
  @chart.series << self
  options.each do |o|
    self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
  end
end

Instance Attribute Details

- (Chart) chart

The chart that owns this series

Returns:



10
11
12
# File 'lib/axlsx/drawing/series.rb', line 10

def chart
  @chart
end

- (Integer) index (readonly)

The index of this series in the chart’s series.

Returns:

  • (Integer)


14
15
16
# File 'lib/axlsx/drawing/series.rb', line 14

def index
  @chart.series.index(self)
end

- (Integer) order

The order of this series in the chart’s series. By default the order is the index of the series.

Returns:

  • (Integer)


18
19
20
# File 'lib/axlsx/drawing/series.rb', line 18

def order
  @order || index
end

- (SeriesTitle) title

The title of the series

Returns:



22
23
24
# File 'lib/axlsx/drawing/series.rb', line 22

def title
  @title
end

Instance Method Details

- (String) to_xml(xml)

Serializes the series

Parameters:

  • xml (Nokogiri::XML::Builder)

    The document builder instance this objects xml will be added to.

Returns:

  • (String)


60
61
62
63
64
65
66
67
# File 'lib/axlsx/drawing/series.rb', line 60

def to_xml(xml)
  xml.send('c:ser') {
    xml.send('c:idx', :val=>index)
    xml.send('c:order', :val=>order || index)        
    title.to_xml(xml) unless title.nil?
    yield xml if block_given?
  }
end