summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorZsolt Kozaroczy <[email protected]>2021-04-26 22:32:49 +0200
committerGitHub <[email protected]>2021-04-26 22:32:49 +0200
commit8d55f0d2ad3c5e4f4c6e9be1cf1e7b065fc25e49 (patch)
treeb68b0e90908246a407c450cee146a066ab1ce0ec /lib
parent6e74fb8db66695649ad0726d88dbecea2dad1722 (diff)
downloadcaxlsx-8d55f0d2ad3c5e4f4c6e9be1cf1e7b065fc25e49.tar.gz
caxlsx-8d55f0d2ad3c5e4f4c6e9be1cf1e7b065fc25e49.zip
Add option to define a series color for the BarSeries (#81)
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/drawing/bar_series.rb19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/axlsx/drawing/bar_series.rb b/lib/axlsx/drawing/bar_series.rb
index d266dd09..0e5d1168 100644
--- a/lib/axlsx/drawing/bar_series.rb
+++ b/lib/axlsx/drawing/bar_series.rb
@@ -22,12 +22,18 @@ module Axlsx
# An array of rgb colors to apply to your bar chart.
attr_reader :colors
+ # The fill color for this series.
+ # Red, green, and blue is expressed as sequence of hex digits, RRGGBB.
+ # @return [String]
+ attr_reader :series_color
+
# Creates a new series
# @option options [Array, SimpleTypedList] data
# @option options [Array, SimpleTypedList] labels
# @option options [String] title
# @option options [String] shape
# @option options [String] colors an array of colors to use when rendering each data point
+ # @option options [String] series_color a color to use when rendering series
# @param [Chart] chart
def initialize(chart, options={})
@shape = :box
@@ -40,6 +46,10 @@ module Axlsx
# @see colors
def colors=(v) DataTypeValidator.validate "BarSeries.colors", [Array], v; @colors = v end
+ def series_color=(v)
+ @series_color = v
+ end
+
# @see shape
def shape=(v)
RestrictionValidator.validate "BarSeries.shape", [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax], v
@@ -60,9 +70,16 @@ module Axlsx
str << '</a:solidFill></c:spPr></c:dPt>'
end
+ if series_color
+ str << '<c:spPr><a:solidFill>'
+ str << ('<a:srgbClr val="' << series_color << '"/>')
+ str << '</a:solidFill>'
+ str << '</c:spPr>'
+ end
+
@labels.to_xml_string(str) unless @labels.nil?
@data.to_xml_string(str) unless @data.nil?
- # this is actually only required for shapes other than box
+ # this is actually only required for shapes other than box
str << ('<c:shape val="' << shape.to_s << '"></c:shape>')
end
end