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=

Methods included from OptionsParser

#parse_options

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

  • series_color (String)

    a color to use when rendering series



37
38
39
40
41
42
43
# File 'lib/axlsx/drawing/bar_series.rb', line 37

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.



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

def colors
  @colors
end

#dataNumDataSource

The data for this series.

Returns:



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

def data
  @data
end

#labelsArray, SimpleTypedList

The labels for this series.

Returns:

  • (Array, SimpleTypedList)


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

def labels
  @labels
end

#series_colorString

The fill color for this series. Red, green, and blue is expressed as sequence of hex digits, RRGGBB.

Returns:

  • (String)


27
28
29
# File 'lib/axlsx/drawing/bar_series.rb', line 27

def series_color
  @series_color
end

#shapeSymbol

The shape of the bars or columns

Returns:

  • (Symbol)

    must be one of [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax]



19
20
21
# File 'lib/axlsx/drawing/bar_series.rb', line 19

def shape
  @shape
end

Instance Method Details

#to_xml_string(str = +'')) ⇒ String

Serializes the object

Parameters:

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

Returns:

  • (String)


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/axlsx/drawing/bar_series.rb', line 64

def to_xml_string(str = +'')
  super(str) do
    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

    if series_color
      str << '<c:spPr><a:solidFill>'
      str << '<a:srgbClr val="' << series_color << '"/>'
      str << '</a:solidFill>'
      str << '</c:spPr>'
    end

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