summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/drawing/chart.rb
diff options
context:
space:
mode:
authorJurriaan Pruis <[email protected]>2015-03-14 16:06:14 +0100
committerJurriaan Pruis <[email protected]>2015-03-14 16:06:14 +0100
commite6b0228fb441fe31eaa09b747f3c3e76ff629dee (patch)
tree6001fb3c96de902d12300bcbc993c99d81ed71e3 /lib/axlsx/drawing/chart.rb
parent73ce1c8d517e6b20cf9dfaf61a685fab65fdf950 (diff)
parent1a9e9d03a2181a928a95be4a642751f34e1a1c34 (diff)
downloadcaxlsx-e6b0228fb441fe31eaa09b747f3c3e76ff629dee.tar.gz
caxlsx-e6b0228fb441fe31eaa09b747f3c3e76ff629dee.zip
Merge pull request #377 from shifakhan/charts_background_color
Background color option for charts
Diffstat (limited to 'lib/axlsx/drawing/chart.rb')
-rw-r--r--lib/axlsx/drawing/chart.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb
index 322f9463..e7fcc9e8 100644
--- a/lib/axlsx/drawing/chart.rb
+++ b/lib/axlsx/drawing/chart.rb
@@ -25,6 +25,7 @@ module Axlsx
@display_blanks_as = :gap
@series_type = Series
@title = Title.new
+ @bg_color = nil
parse_options options
start_at(*options[:start_at]) if options[:start_at]
end_at(*options[:end_at]) if options[:end_at]
@@ -93,6 +94,10 @@ module Axlsx
# Default :gap (although this really should vary by chart type and grouping)
attr_reader :display_blanks_as
+ # Background color for the chart
+ # @return [String]
+ attr_reader :bg_color
+
# The relationship object for this chart.
# @return [Relationship]
def relationship
@@ -162,6 +167,12 @@ module Axlsx
@series.last
end
+ # Assigns a background color to chart area
+ def bg_color=(v)
+ DataTypeValidator.validate(:color, Color, Color.new(:rgb => v))
+ @bg_color = v
+ end
+
# Serializes the object
# @param [String] str
# @return [String]
@@ -192,6 +203,16 @@ module Axlsx
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"/>'