Class: Axlsx::Chart
- Inherits:
-
Object
- Object
- Axlsx::Chart
- Defined in:
- lib/axlsx/drawing/chart.rb
Overview
Worksheet#add_chart is the recommended way to create charts for your worksheets.
A Chart is the superclass for specific charts
Direct Known Subclasses
Instance Attribute Summary collapse
-
#end_at ⇒ Marker
readonly
The ending marker for this chart.
-
#graphic_frame ⇒ GraphicFrame
readonly
A reference to the graphic frame that owns this chart.
-
#index ⇒ Integer
readonly
The index of this chart in the workbooks charts collection.
-
#pn ⇒ String
readonly
The part name for this chart.
-
#series ⇒ SimpleTypedList
readonly
A collection of series objects that are applied to the chart.
-
#series_type ⇒ Series
readonly
The type of series to use for this chart.
-
#show_legend ⇒ Boolean
Show the legend in the chart.
-
#start_at ⇒ Marker
readonly
The starting marker for this chart.
-
#style ⇒ Integer
The style for the chart.
-
#title ⇒ Title
The title object for the chart.
-
#view3D ⇒ Object
The 3D view properties for the chart.
Instance Method Summary collapse
-
#add_series(options = {}) ⇒ Series
Adds a new series to the chart’s series collection.
-
#initialize(frame, options = {}) {|_self| ... } ⇒ Chart
constructor
Creates a new chart object.
-
#to_xml ⇒ Object
Chart Serialization serializes the chart.
Constructor Details
#initialize(frame, options = {}) {|_self| ... } ⇒ Chart
Creates a new chart object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/axlsx/drawing/chart.rb', line 58 def initialize(frame, ={}) @style = 2 @graphic_frame=frame @graphic_frame.anchor.drawing.worksheet.workbook.charts << self @series = SimpleTypedList.new Series @show_legend = true @series_type = Series .each do |o| self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" end yield self if block_given? end |
Instance Attribute Details
#end_at ⇒ Marker
The ending marker for this chart
48 49 50 |
# File 'lib/axlsx/drawing/chart.rb', line 48 def end_at @end_at end |
#graphic_frame ⇒ GraphicFrame (readonly)
A reference to the graphic frame that owns this chart
21 22 23 |
# File 'lib/axlsx/drawing/chart.rb', line 21 def graphic_frame @graphic_frame end |
#index ⇒ Integer (readonly)
The index of this chart in the workbooks charts collection
33 34 35 |
# File 'lib/axlsx/drawing/chart.rb', line 33 def index @index end |
#pn ⇒ String (readonly)
The part name for this chart
37 38 39 |
# File 'lib/axlsx/drawing/chart.rb', line 37 def pn @pn end |
#series ⇒ SimpleTypedList (readonly)
A collection of series objects that are applied to the chart
25 26 27 |
# File 'lib/axlsx/drawing/chart.rb', line 25 def series @series end |
#series_type ⇒ Series (readonly)
The type of series to use for this chart
29 30 31 |
# File 'lib/axlsx/drawing/chart.rb', line 29 def series_type @series_type end |
#show_legend ⇒ Boolean
Show the legend in the chart
52 53 54 |
# File 'lib/axlsx/drawing/chart.rb', line 52 def show_legend @show_legend end |
#start_at ⇒ Marker
The starting marker for this chart
44 45 46 |
# File 'lib/axlsx/drawing/chart.rb', line 44 def start_at @start_at end |
#style ⇒ Integer
The style for the chart. see ECMA Part 1 §21.2.2.196
14 15 16 |
# File 'lib/axlsx/drawing/chart.rb', line 14 def style @style end |
#title ⇒ Title
The title object for the chart.
9 10 11 |
# File 'lib/axlsx/drawing/chart.rb', line 9 def title @title end |
#view3D ⇒ Object
The 3D view properties for the chart
17 18 19 |
# File 'lib/axlsx/drawing/chart.rb', line 17 def view3D @view3D end |
Instance Method Details
#add_series(options = {}) ⇒ Series
Adds a new series to the chart’s series collection.
94 95 96 97 |
# File 'lib/axlsx/drawing/chart.rb', line 94 def add_series(={}) @series_type.new(self, ) @series.last end |
#to_xml ⇒ Object
Chart Serialization serializes the chart
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/axlsx/drawing/chart.rb', line 101 def to_xml builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml| xml.send('c:chartSpace',:'xmlns:c' => XML_NS_C, :'xmlns:a' => XML_NS_A) { xml.send('c:date1904', :val=>Axlsx::Workbook.date1904) xml.send('c:style', :val=>style) xml.send('c:chart') { @title.to_xml(xml) unless @title.nil? @view3D.to_xml(xml) unless @view3D.nil? xml.send('c:plotArea') { xml.send('c:layout') yield xml if block_given? } if @show_legend xml.send('c:legend') { xml.send('c:legendPos', :val => "r") xml.send('c:layout') } end } } end builder.to_xml end |