diff options
| author | Randy Morgan <[email protected]> | 2012-04-27 19:18:05 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-04-27 19:18:05 +0900 |
| commit | 956117947416cba4ce21737ae0c2a431e4865b8e (patch) | |
| tree | 045b5993105166eedb9be3760e94716461e1d2f4 /lib/axlsx/drawing/bar_series.rb | |
| parent | 3748326fe3c09515077ab97f4d2a2b0638e823fd (diff) | |
| download | caxlsx-956117947416cba4ce21737ae0c2a431e4865b8e.tar.gz caxlsx-956117947416cba4ce21737ae0c2a431e4865b8e.zip | |
colored chart series and examples. Still need to workout scatter as it uses line and shape
Diffstat (limited to 'lib/axlsx/drawing/bar_series.rb')
| -rw-r--r-- | lib/axlsx/drawing/bar_series.rb | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/axlsx/drawing/bar_series.rb b/lib/axlsx/drawing/bar_series.rb index 86ae6367..63c20a31 100644 --- a/lib/axlsx/drawing/bar_series.rb +++ b/lib/axlsx/drawing/bar_series.rb @@ -20,19 +20,27 @@ module Axlsx # @return [Symbol] attr_reader :shape + # An array of rgb colors to apply to your bar chart. + attr_reader :colors + # 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 # @param [Chart] chart def initialize(chart, options={}) @shape = :box + @colors = [] super(chart, options) self.labels = CatAxisData.new(options[:labels]) unless options[:labels].nil? self.data = ValAxisData.new(options[:data]) unless options[:data].nil? end + # @see colors + def colors=(v) DataTypeValidator.validate "BarSeries.colors", [Array], v; @colors = v end + # The shabe of the bars or columns # must be one of [:percentStacked, :clustered, :standard, :stacked] def shape=(v) @@ -45,9 +53,16 @@ module Axlsx # @return [String] def to_xml_string(str = '') super(str) do |str_inner| + colors.each_with_index do |c, index| + str << '<c:dPt>' + str << '<c:idx val="' << index.to_s << '"/>' + str << '<c:spPr><a:solidFill>' + str << '<a:srgbClr val="' << c << '"/>' + str << '</a:solidFill></c:spPr></c:dPt>' + end @labels.to_xml_string(str_inner) unless @labels.nil? @data.to_xml_string(str_inner) unless @data.nil? - str_inner << '<shape val="' << @shape.to_s << '"/>' + str_inner << '<c:shape val="' << @shape.to_s << '"/>' end end |
