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)
-
- (Marker) end_at
The ending marker for this chart.
-
- (GraphicFrame) graphic_frame
readonly
A reference to the graphic frame that owns this chart.
-
- (Integer) index
readonly
The index of this chart in the workbooks charts collection.
-
- (String) pn
readonly
The part name for this chart.
-
- (SimpleTypedList) series
readonly
A collection of series objects that are applied to the chart.
-
- (Series) series_type
readonly
The type of series to use for this chart.
-
- (Boolean) show_legend
Show the legend in the chart.
-
- (Marker) start_at
The starting marker for this chart.
-
- (Title) title
The title object for the chart.
-
- (Object) view3D
The 3D view properties for the chart.
Instance Method Summary (collapse)
-
- (Series) add_series(options = {})
Adds a new series to the chart’s series collection.
-
- (Chart) initialize(frame, options = {}) {|_self| ... }
constructor
Creates a new chart object.
-
- (Object) to_xml
Chart Serialization serializes the chart.
Constructor Details
- (Chart) initialize(frame, options = {}) {|_self| ... }
Creates a new chart object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/axlsx/drawing/chart.rb', line 52 def initialize(frame, ={}) @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
- (Marker) end_at
The ending marker for this chart
42 43 44 |
# File 'lib/axlsx/drawing/chart.rb', line 42 def end_at @end_at end |
- (GraphicFrame) graphic_frame (readonly)
A reference to the graphic frame that owns this chart
15 16 17 |
# File 'lib/axlsx/drawing/chart.rb', line 15 def graphic_frame @graphic_frame end |
- (Integer) index (readonly)
The index of this chart in the workbooks charts collection
27 28 29 |
# File 'lib/axlsx/drawing/chart.rb', line 27 def index @graphic_frame.anchor.drawing.worksheet.workbook.charts.index(self) end |
- (String) pn (readonly)
The part name for this chart
31 32 33 |
# File 'lib/axlsx/drawing/chart.rb', line 31 def pn "#{CHART_PN % (index+1)}" end |
- (SimpleTypedList) series (readonly)
A collection of series objects that are applied to the chart
19 20 21 |
# File 'lib/axlsx/drawing/chart.rb', line 19 def series @series end |
- (Series) series_type (readonly)
The type of series to use for this chart
23 24 25 |
# File 'lib/axlsx/drawing/chart.rb', line 23 def series_type @series_type end |
- (Boolean) show_legend
Show the legend in the chart
46 47 48 |
# File 'lib/axlsx/drawing/chart.rb', line 46 def show_legend @show_legend end |
- (Marker) start_at
The starting marker for this chart
38 39 40 |
# File 'lib/axlsx/drawing/chart.rb', line 38 def start_at @start_at end |
- (Title) title
The title object for the chart.
8 9 10 |
# File 'lib/axlsx/drawing/chart.rb', line 8 def title @title end |
- (Object) view3D
The 3D view properties for the chart
11 12 13 |
# File 'lib/axlsx/drawing/chart.rb', line 11 def view3D @view3D end |
Instance Method Details
- (Series) add_series(options = {})
Adds a new series to the chart’s series collection.
85 86 87 88 |
# File 'lib/axlsx/drawing/chart.rb', line 85 def add_series(={}) @series_type.new(self, ) @series.last end |
- (Object) to_xml
Chart Serialization serializes the chart
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/axlsx/drawing/chart.rb', line 92 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: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 |