Class: Axlsx::Chart
- Inherits:
-
Object
- Object
- Axlsx::Chart
- Includes:
- OptionsParser
- 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
AreaChart, Bar3DChart, BarChart, BubbleChart, LineChart, Pie3DChart, ScatterChart
Instance Attribute Summary collapse
-
#bg_color ⇒ String
Background color for the chart.
-
#display_blanks_as ⇒ Symbol
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 Default :gap (although this really should vary by chart type and grouping).
-
#graphic_frame ⇒ GraphicFrame
readonly
A reference to the graphic frame that owns this chart.
-
#legend_position ⇒ Symbol
Set the location of the chart's legend.
-
#plot_visible_only ⇒ Boolean
Whether only data from visible cells should be plotted.
-
#rounded_corners ⇒ Boolean
Whether the chart area shall have rounded corners.
-
#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.
-
#vary_colors ⇒ Boolean
Indicates that colors should be varied by datum.
-
#view_3D ⇒ Object
(also: #view3D)
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.
-
#d_lbls ⇒ Object
TODO data labels!.
-
#end_at(x = 10, y = 10) ⇒ 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.
-
#relationship ⇒ Relationship
The relationship object for this chart.
-
#start_at(x = 0, y = 0) ⇒ Marker
This is a short cut method to set the anchor start marker position If you need finer granularity in positioning use.
-
#title_size=(v) ⇒ Object
The size of the Title object of the chart.
-
#to ⇒ Object
backwards compatibility to allow chart.to and chart.from access to anchor markers.
-
#to_xml_string(str = '') ⇒ String
Serializes the object.
Methods included from OptionsParser
Constructor Details
#initialize(frame, options = {}) {|_self| ... } ⇒ Chart
Creates a new chart object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/axlsx/drawing/chart.rb', line 19 def initialize(frame, ={}) @style = 18 @view_3D = nil @graphic_frame=frame @graphic_frame.anchor.drawing.worksheet.workbook.charts << self @series = SimpleTypedList.new Series @show_legend = true @legend_position = :r @display_blanks_as = :gap @series_type = Series @title = Title.new @bg_color = nil @plot_visible_only = true @rounded_corners = true start_at(*[:start_at]) if [:start_at] end_at(*[:end_at]) if [:end_at] yield self if block_given? end |
Instance Attribute Details
#bg_color ⇒ String
Background color for the chart
103 104 105 |
# File 'lib/axlsx/drawing/chart.rb', line 103 def bg_color @bg_color end |
#display_blanks_as ⇒ Symbol
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 Default :gap (although this really should vary by chart type and grouping)
99 100 101 |
# File 'lib/axlsx/drawing/chart.rb', line 99 def display_blanks_as @display_blanks_as end |
#graphic_frame ⇒ GraphicFrame (readonly)
A reference to the graphic frame that owns this chart
45 46 47 |
# File 'lib/axlsx/drawing/chart.rb', line 45 def graphic_frame @graphic_frame end |
#legend_position ⇒ Symbol
The following are allowed :b :l :r :t :tr
Set the location of the chart's legend
90 91 92 |
# File 'lib/axlsx/drawing/chart.rb', line 90 def legend_position @legend_position end |
#plot_visible_only ⇒ Boolean
Whether only data from visible cells should be plotted.
107 108 109 |
# File 'lib/axlsx/drawing/chart.rb', line 107 def plot_visible_only @plot_visible_only end |
#rounded_corners ⇒ Boolean
Whether the chart area shall have rounded corners.
111 112 113 |
# File 'lib/axlsx/drawing/chart.rb', line 111 def rounded_corners @rounded_corners end |
#series ⇒ SimpleTypedList (readonly)
A collection of series objects that are applied to the chart
49 50 51 |
# File 'lib/axlsx/drawing/chart.rb', line 49 def series @series end |
#series_type ⇒ Series (readonly)
The type of series to use for this chart.
53 54 55 |
# File 'lib/axlsx/drawing/chart.rb', line 53 def series_type @series_type end |
#show_legend ⇒ Boolean
Show the legend in the chart
79 80 81 |
# File 'lib/axlsx/drawing/chart.rb', line 79 def show_legend @show_legend end |
#style ⇒ Integer
The style for the chart. see ECMA Part 1 ยง21.2.2.196
75 76 77 |
# File 'lib/axlsx/drawing/chart.rb', line 75 def style @style end |
#title ⇒ Title
The title object for the chart.
70 71 72 |
# File 'lib/axlsx/drawing/chart.rb', line 70 def title @title end |
#vary_colors ⇒ Boolean
Indicates that colors should be varied by datum
62 63 64 |
# File 'lib/axlsx/drawing/chart.rb', line 62 def vary_colors @vary_colors end |
#view_3D ⇒ Object Also known as: view3D
The 3D view properties for the chart
40 41 42 |
# File 'lib/axlsx/drawing/chart.rb', line 40 def view_3D @view_3D end |
Instance Method Details
#add_series(options = {}) ⇒ Series
Adds a new series to the chart's series collection.
184 185 186 187 |
# File 'lib/axlsx/drawing/chart.rb', line 184 def add_series(={}) @series_type.new(self, ) @series.last end |
#d_lbls ⇒ Object
TODO data labels!
56 57 58 |
# File 'lib/axlsx/drawing/chart.rb', line 56 def d_lbls @d_lbls ||= DLbls.new(self.class) end |
#end_at(x = 10, y = 10) ⇒ 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
289 290 291 |
# File 'lib/axlsx/drawing/chart.rb', line 289 def end_at(x=10, y=10) @graphic_frame.anchor.end_at(x, 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
177 178 179 |
# File 'lib/axlsx/drawing/chart.rb', line 177 def from @graphic_frame.anchor.from end |
#index ⇒ Integer
The index of this chart in the workbooks charts collection
121 122 123 |
# File 'lib/axlsx/drawing/chart.rb', line 121 def index @graphic_frame.anchor.drawing.worksheet.workbook.charts.index(self) end |
#pn ⇒ String
The part name for this chart
127 128 129 |
# File 'lib/axlsx/drawing/chart.rb', line 127 def pn "#{CHART_PN % (index+1)}" end |
#relationship ⇒ Relationship
The relationship object for this chart.
115 116 117 |
# File 'lib/axlsx/drawing/chart.rb', line 115 def relationship Relationship.new(self, CHART_R, "../#{pn}") end |
#start_at(x = 0, y = 0) ⇒ Marker
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
reference or cell to use in setting the start marker position.
278 279 280 |
# File 'lib/axlsx/drawing/chart.rb', line 278 def start_at(x=0, y=0) @graphic_frame.anchor.start_at(x, y) end |
#title_size=(v) ⇒ Object
The size of the Title object of the chart.
146 147 148 |
# File 'lib/axlsx/drawing/chart.rb', line 146 def title_size=(v) @title.text_size = v unless v.to_s.empty? 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
171 172 173 |
# File 'lib/axlsx/drawing/chart.rb', line 171 def to @graphic_frame.anchor.to end |
#to_xml_string(str = '') ⇒ String
Serializes the object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/axlsx/drawing/chart.rb', line 208 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:roundedCorners val="' << rounded_corners.to_s << '"/>') str << ('<c:style val="' << style.to_s << '"/>') str << '<c:chart>' @title.to_xml_string(str) unless @title.empty? 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="' << @legend_position.to_s << '"/>') str << '<c:layout/>' str << '<c:overlay val="0"/>' str << '</c:legend>' end str << ('<c:plotVisOnly val="' << @plot_visible_only.to_s << '"/>') str << ('<c:dispBlanksAs val="' << display_blanks_as.to_s << '"/>') str << '<c:showDLblsOverMax val="1"/>' str << '</c:chart>' if bg_color str << '<c:spPr>' str << '<a:solidFill>' str << '<a:srgbClr val="' << bg_color << '"/>' str << '</a:solidFill>' str << '<a:ln>' str << '<a:noFill/>' str << '</a:ln>' str << '</c:spPr>' end 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 |