class Axlsx::Chart

A Chart is the superclass for specific charts @note Worksheet#add_chart is the recommended way to create charts for your worksheets. @see README for examples

Attributes

display_blanks_as[R]

How to display blank values Options are

  • gap: Display nothing

  • span: Not sure what this does

  • zero: Display as if the value were zero, not blank

@return [Symbol] Default :gap (although this really should vary by chart type and grouping)

graphic_frame[R]

A reference to the graphic frame that owns this chart @return [GraphicFrame]

series[R]

A collection of series objects that are applied to the chart @return [SimpleTypedList]

series_type[R]

The type of series to use for this chart. @return [Series]

show_legend[R]

Show the legend in the chart @return [Boolean]

style[R]

The style for the chart. see ECMA Part 1 §21.2.2.196 @return [Integer]

title[R]

The title object for the chart. @return [Title]

vary_colors[R]

Indicates that colors should be varied by datum @return [Boolean]

view3D[R]

The 3D view properties for the chart

view_3D[R]

The 3D view properties for the chart

Public Class Methods

new(frame, options={}) { |self| ... } click to toggle source

Creates a new chart object @param [GraphicalFrame] frame The frame that holds this chart. @option options [Cell, String] title @option options [Boolean] show_legend @option options [Array|String|Cell] start_at The X, Y coordinates defining the top left corner of the chart. @option options [Array|String|Cell] end_at The X, Y coordinates defining the bottom right corner of the chart.

# File lib/axlsx/drawing/chart.rb, line 16
def initialize(frame, options={})
  @style = 18
  @view_3D = nil
  @graphic_frame=frame
  @graphic_frame.anchor.drawing.worksheet.workbook.charts << self
  @series = SimpleTypedList.new Series
  @show_legend = true
  @display_blanks_as = :gap
  @series_type = Series
  @title = Title.new
  parse_options options
  start_at(*options[:start_at]) if options[:start_at]
  end_at(*options[:end_at]) if options[:end_at]
  yield self if block_given?
end

Public Instance Methods

add_series(options={}) click to toggle source

Adds a new series to the chart’s series collection. @return [Series] @see Series

# File lib/axlsx/drawing/chart.rb, line 144
def add_series(options={})
  @series_type.new(self, options)
  @series.last
end
d_lbls() click to toggle source

TODO data labels!

# File lib/axlsx/drawing/chart.rb, line 49
def d_lbls
  @d_lbls ||= DLbls.new(self.class)
end
display_blanks_as=(v) click to toggle source

How to display blank values @see display_blanks_as @param [Symbol] v @return [Symbol]

# File lib/axlsx/drawing/chart.rb, line 122
def display_blanks_as=(v) Axlsx::validate_display_blanks_as(v); @display_blanks_as = v; end
end_at(x=10, y=10) click to toggle source

This is a short cut method to set the end anchor position If you need finer granularity in positioning use graphic_frame.anchor.to.colOff / rowOff @param [Integer] x The column - default 10 @param [Integer] y The row - default 10 @return [Marker] @see start_at

# File lib/axlsx/drawing/chart.rb, line 222
def end_at(x=10, y=10)
  @graphic_frame.anchor.end_at(x, y)
end
from() click to toggle source

backwards compatibility to allow chart.to and chart.from access to anchor markers @note This will be disconinued in version 2.0.0. please use the start_at method

# File lib/axlsx/drawing/chart.rb, line 137
def from
  @graphic_frame.anchor.from
end
index() click to toggle source

The index of this chart in the workbooks charts collection @return [Integer]

# File lib/axlsx/drawing/chart.rb, line 91
def index
  @graphic_frame.anchor.drawing.worksheet.workbook.charts.index(self)
end
pn() click to toggle source

The part name for this chart @return [String]

# File lib/axlsx/drawing/chart.rb, line 97
def pn
  "#{CHART_PN % (index+1)}"
end
relationship() click to toggle source

The relationship object for this chart. @return [Relationship]

# File lib/axlsx/drawing/chart.rb, line 85
def relationship
  Relationship.new(self, CHART_R, "../#{pn}")
end
show_legend=(v) click to toggle source

Show the legend in the chart @param [Boolean] v @return [Boolean]

# File lib/axlsx/drawing/chart.rb, line 116
def show_legend=(v) Axlsx::validate_boolean(v); @show_legend = v; end
start_at(x=0, y=0) click to toggle source

This is a short cut method to set the anchor start marker position If you need finer granularity in positioning use

This helper method acceps a fairly wide range of inputs exampled below

@example

start_at 0, 5 # The anchor start marker is set to 6th row of
the first column

start_at [0, 5] # The anchor start marker is set to start on the 6th row
of the first column

start_at "C1" # The anchor start marker is set to start on the first row
of the third column

start_at sheet.rows.first.cells.last # The anchor start
marker is set to the location of a specific cell.

@param [Array|String|Cell] x the column, coordinates, string reference or cell to use in setting the start marker position. @param [Integer] y The row @return [Marker]

# File lib/axlsx/drawing/chart.rb, line 211
def start_at(x=0, y=0)
  @graphic_frame.anchor.start_at(x, y)
end
style=(v) click to toggle source

The style for the chart. see ECMA Part 1 §21.2.2.196 @param [Integer] v must be between 1 and 48

# File lib/axlsx/drawing/chart.rb, line 127
def style=(v) DataTypeValidator.validate "Chart.style", Integer, v, lambda { |arg| arg >= 1 && arg <= 48 }; @style = v; end
title=(v) click to toggle source

The title object for the chart. @param [String, Cell] v @return [Title]

# File lib/axlsx/drawing/chart.rb, line 104
def title=(v)
  DataTypeValidator.validate "#{self.class}.title", [String, Cell], v
  if v.is_a?(String)
    @title.text = v
  elsif v.is_a?(Cell)
    @title.cell = v
  end
end
to() click to toggle source

backwards compatibility to allow chart.to and chart.from access to anchor markers @note This will be disconinued in version 2.0.0. Please use the end_at method

# File lib/axlsx/drawing/chart.rb, line 131
def to
  @graphic_frame.anchor.to
end
to_xml_string(str = '') { || ... } click to toggle source

Serializes the object @param [String] str @return [String]

# File lib/axlsx/drawing/chart.rb, line 152
def to_xml_string(str = '')
  str << '<?xml version="1.0" encoding="UTF-8"?>'
  str << ('<c:chartSpace xmlns:c="' << XML_NS_C << '" xmlns:a="' << XML_NS_A << '" xmlns:r="' << XML_NS_R << '">')
  str << ('<c:date1904 val="' << Axlsx::Workbook.date1904.to_s << '"/>')
  str << ('<c:style val="' << style.to_s << '"/>')
  str << '<c:chart>'
  @title.to_xml_string str
  str << ('<c:autoTitleDeleted val="' << (@title == nil).to_s << '"/>')
  @view_3D.to_xml_string(str) if @view_3D
  str << '<c:floor><c:thickness val="0"/></c:floor>'
  str << '<c:sideWall><c:thickness val="0"/></c:sideWall>'
  str << '<c:backWall><c:thickness val="0"/></c:backWall>'
  str << '<c:plotArea>'
  str << '<c:layout/>'
  yield if block_given?
  str << '</c:plotArea>'
  if @show_legend
    str << '<c:legend>'
    str << '<c:legendPos val="r"/>'
    str << '<c:layout/>'
    str << '<c:overlay val="0"/>'
    str << '</c:legend>'
  end
  str << '<c:plotVisOnly val="1"/>'
  str << ('<c:dispBlanksAs val="' << display_blanks_as.to_s << '"/>')
  str << '<c:showDLblsOverMax val="1"/>'
  str << '</c:chart>'
  str << '<c:printSettings>'
  str << '<c:headerFooter/>'
  str << '<c:pageMargins b="1.0" l="0.75" r="0.75" t="1.0" header="0.5" footer="0.5"/>'
  str << '<c:pageSetup/>'
  str << '</c:printSettings>'
  str << '</c:chartSpace>'
end
vary_colors=(v) click to toggle source

Configures the vary_colors options for this chart @param [Boolean] v The value to set

# File lib/axlsx/drawing/chart.rb, line 59
def vary_colors=(v) Axlsx::validate_boolean(v); @vary_colors = v; end
view3D=(v)
Alias for: view_3D=
view_3D=(v) click to toggle source

sets the view_3D object for the chart

# File lib/axlsx/drawing/chart.rb, line 227
def view_3D=(v) DataTypeValidator.validate "#{self.class}.view_3D", View3D, v; @view_3D = v; end
Also aliased as: view3D=