Class: Axlsx::LineChart

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

Overview

The LineChart is a two dimentional line chart (who would have guessed?) that you can add to your worksheet.

Examples:

Creating a chart

# This example creates a line in a single sheet.
require "rubygems" # if that is your preferred way to manage gems!
require "axlsx"

p = Axlsx::Package.new
ws = p.workbook.add_worksheet
ws.add_row ["This is a chart with no data in the sheet"]

chart = ws.add_chart(Axlsx::LineChart, :start_at=> [0,1], :end_at=>[0,6], :title=>"Most Popular Pets")
chart.add_series :data => [1, 9, 10], :labels => ["Slimy Reptiles", "Fuzzy Bunnies", "Rottweiler"]

See Also:

Direct Known Subclasses

Line3DChart

Instance Attribute Summary collapse

Attributes inherited from Chart

#bg_color, #display_blanks_as, #graphic_frame, #legend_position, #plot_visible_only, #rounded_corners, #series, #series_type, #show_legend, #style, #title, #vary_colors, #view_3D

Instance Method Summary collapse

Methods inherited from Chart

#add_series, #d_lbls, #end_at, #from, #index, #pn, #relationship, #start_at, #title_size=, #to

Methods included from OptionsParser

#parse_options

Constructor Details

#initialize(frame, options = {}) ⇒ LineChart

Creates a new line chart object

Parameters:

  • frame (GraphicFrame)

    The workbook that owns this chart.

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

    a customizable set of options

Options Hash (options):

  • title (Cell, String)
  • show_legend (Boolean)
  • grouping (Symbol)

See Also:



47
48
49
50
51
52
53
# File 'lib/axlsx/drawing/line_chart.rb', line 47

def initialize(frame, options = {})
  @vary_colors = false
  @grouping = :standard
  super(frame, options)
  @series_type = LineSeries
  @d_lbls = nil
end

Instance Attribute Details

#groupingSymbol

must be one of [:percentStacked, :clustered, :standard, :stacked]

Returns:

  • (Symbol)


39
40
41
# File 'lib/axlsx/drawing/line_chart.rb', line 39

def grouping
  @grouping
end

Instance Method Details

#axesAxes

The axes for this chart. LineCharts have a category and value axis.

Returns:



94
95
96
# File 'lib/axlsx/drawing/line_chart.rb', line 94

def axes
  @axes ||= Axes.new(cat_axis: CatAxis, val_axis: ValAxis)
end

#cat_axisCatAxis Also known as: catAxis

the category axis

Returns:



25
26
27
# File 'lib/axlsx/drawing/line_chart.rb', line 25

def cat_axis
  axes[:cat_axis]
end

#node_nameString

The node name to use in serialization. As LineChart is used as the base class for Liine3DChart we need to be sure to serialize the chart based on the actual class type and not a fixed node name.

Returns:

  • (String)


65
66
67
68
69
70
71
72
# File 'lib/axlsx/drawing/line_chart.rb', line 65

def node_name
  path = self.class.name
  if i = path.rindex('::')
    path = path[(i + 2)..-1]
  end
  path[0] = path[0].chr.downcase
  path
end

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

Serializes the object

Parameters:

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

Returns:

  • (String)


77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/axlsx/drawing/line_chart.rb', line 77

def to_xml_string(str = +'')
  super(str) do
    str << "<c:" << node_name << ">"
    str << '<c:grouping val="' << grouping.to_s << '"/>'
    str << '<c:varyColors val="' << vary_colors.to_s << '"/>'
    @series.each { |ser| ser.to_xml_string(str) }
    @d_lbls.to_xml_string(str) if @d_lbls
    yield if block_given?
    axes.to_xml_string(str, ids: true)
    str << "</c:" << node_name << ">"
    axes.to_xml_string(str)
  end
end

#val_axisValAxis Also known as: valAxis

the category axis

Returns:



32
33
34
# File 'lib/axlsx/drawing/line_chart.rb', line 32

def val_axis
  axes[:val_axis]
end