Class: Axlsx::PieSeries

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

Overview

Note:

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

A PieSeries defines the data and labels and explosion for pie charts series.

Instance Attribute Summary collapse

Attributes inherited from Series

#chart, #title

Instance Method Summary collapse

Methods inherited from Series

#index, #order, #order=

Methods included from OptionsParser

#parse_options

Constructor Details

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

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)
  • explosion (Integer)


31
32
33
34
35
36
37
# File 'lib/axlsx/drawing/pie_series.rb', line 31

def initialize(chart, options={})
  @explosion = nil
  @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.



23
24
25
# File 'lib/axlsx/drawing/pie_series.rb', line 23

def colors
  @colors
end

#dataSimpleTypedList

The data for this series.

Returns:

  • (SimpleTypedList)


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

def data
  @data
end

#explosionIntegert

The explosion for this series

Returns:

  • (Integert)


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

def explosion
  @explosion
end

#labelsSimpleTypedList

The labels for this series.

Returns:

  • (SimpleTypedList)


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

def labels
  @labels
end

Instance Method Details

#to_xml_string(str = '') ⇒ String

Serializes the object

Parameters:

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

Returns:

  • (String)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/axlsx/drawing/pie_series.rb', line 48

def to_xml_string(str = '')
  super(str) do |str_inner|
    str_inner << '<c:explosion val="' << @explosion << '"/>' unless @explosion.nil?
    colors.each_with_index do |c, index|
      str << '<c:dPt>'
      str << '<c:idx val="' << index.to_s << '"/>'
      str << '<c:spPr><a:solidFill>'
      str << '<a:srgbClr val="' << c << '"/>'
      str << '</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?
  end
  str
end