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
-
#graphic_frame ⇒ GraphicFrame
readonly
A reference to the graphic frame that owns 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.
-
#style ⇒ Integer
The style for the chart.
-
#title ⇒ Title
The title object for the chart.
-
#view3D ⇒ Object
readonly
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.
-
#end_at(x, y = 0) ⇒ Marker
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.
-
#from ⇒ Object
backwards compatibility to allow chart.to and chart.from access to anchor markers.
-
#index ⇒ Integer
The index of this chart in the workbooks charts collection.
-
#initialize(frame, options = {}) {|_self| ... } ⇒ Chart
constructor
Creates a new chart object.
-
#pn ⇒ String
The part name for this chart.
-
#start_at(x, y = 0) ⇒ Marker
This is a short cut method to set the start anchor position If you need finer granularity in positioning use graphic_frame.anchor.from.colOff / rowOff.
-
#to ⇒ Object
backwards compatibility to allow chart.to and chart.from access to anchor markers.
-
#to_xml_string(str = '') {|str| ... } ⇒ String
Serializes the object.
Constructor Details
#initialize(frame, options = {}) {|_self| ... } ⇒ Chart
Creates a new chart object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/axlsx/drawing/chart.rb', line 44 def initialize(frame, ={}) @style = 2 @view3D = nil @graphic_frame=frame @graphic_frame.anchor.drawing.worksheet.workbook.charts << self @series = SimpleTypedList.new Series @show_legend = true @series_type = Series @title = Title.new .each do |o| self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" end start_at(*[:start_at]) if [:start_at] end_at(*[:end_at]) if [:start_at] yield self if block_given? end |
Instance Attribute Details
#graphic_frame ⇒ GraphicFrame (readonly)
A reference to the graphic frame that owns this chart
14 15 16 |
# File 'lib/axlsx/drawing/chart.rb', line 14 def graphic_frame @graphic_frame end |
#series ⇒ SimpleTypedList (readonly)
A collection of series objects that are applied to the chart
18 19 20 |
# File 'lib/axlsx/drawing/chart.rb', line 18 def series @series end |
#series_type ⇒ Series (readonly)
The type of series to use for this chart.
22 23 24 |
# File 'lib/axlsx/drawing/chart.rb', line 22 def series_type @series_type end |
#show_legend ⇒ Boolean
Show the legend in the chart
38 39 40 |
# File 'lib/axlsx/drawing/chart.rb', line 38 def show_legend @show_legend end |
#style ⇒ Integer
The style for the chart. see ECMA Part 1 §21.2.2.196
34 35 36 |
# File 'lib/axlsx/drawing/chart.rb', line 34 def style @style end |
#title ⇒ Title
The title object for the chart.
29 30 31 |
# File 'lib/axlsx/drawing/chart.rb', line 29 def title @title end |
#view3D ⇒ Object
The 3D view properties for the chart
10 11 12 |
# File 'lib/axlsx/drawing/chart.rb', line 10 def view3D @view3D end |
Instance Method Details
#add_series(options = {}) ⇒ Series
Adds a new series to the chart’s series collection.
111 112 113 114 |
# File 'lib/axlsx/drawing/chart.rb', line 111 def add_series(={}) @series_type.new(self, ) @series.last end |
#end_at(x, y = 0) ⇒ Marker
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
168 169 170 171 172 |
# File 'lib/axlsx/drawing/chart.rb', line 168 def end_at(x, y=0) x, y = *parse_coord_args(x, y) @graphic_frame.anchor.to.col = x @graphic_frame.anchor.to.row = y end |
#from ⇒ Object
This will be disconinued in version 2.0.0. please use the start_at method
backwards compatibility to allow chart.to and chart.from access to anchor markers
104 105 106 |
# File 'lib/axlsx/drawing/chart.rb', line 104 def from @graphic_frame.anchor.from end |
#index ⇒ Integer
The index of this chart in the workbooks charts collection
63 64 65 |
# File 'lib/axlsx/drawing/chart.rb', line 63 def index @graphic_frame.anchor.drawing.worksheet.workbook.charts.index(self) end |
#pn ⇒ String
The part name for this chart
69 70 71 |
# File 'lib/axlsx/drawing/chart.rb', line 69 def pn "#{CHART_PN % (index+1)}" end |
#start_at(x, y = 0) ⇒ Marker
This is a short cut method to set the start anchor position If you need finer granularity in positioning use graphic_frame.anchor.from.colOff / rowOff
156 157 158 159 160 |
# File 'lib/axlsx/drawing/chart.rb', line 156 def start_at(x, y=0) x, y = *parse_coord_args(x, y) @graphic_frame.anchor.from.col = x @graphic_frame.anchor.from.row = y end |
#to ⇒ Object
This will be disconinued in version 2.0.0. Please use the end_at method
backwards compatibility to allow chart.to and chart.from access to anchor markers
98 99 100 |
# File 'lib/axlsx/drawing/chart.rb', line 98 def to @graphic_frame.anchor.to end |
#to_xml_string(str = '') {|str| ... } ⇒ String
Serializes the object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/axlsx/drawing/chart.rb', line 119 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 << '">' str << '<c:date1904 val="' << Axlsx::Workbook.date1904.to_s << '"/>' str << '<c:style val="' << style.to_s << '"/>' str << '<c:chart>' @title.to_xml_string str # do these need the c: namespace as well??? str << '<c:autoTitleDeleted val="0"/>' @view3D.to_xml_string(str) if @view3D 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 str 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="zero"/>' str << '<c:showDLblsOverMax val="1"/>' str << '</c:chart>' str << '</c:chartSpace>' end |