Class: Axlsx::Bar3DChart

Inherits:
Chart
  • Object
show all
Defined in:
lib/axlsx/drawing/bar_3D_chart.rb

Overview

The Bar3DChart is a three dimentional barchart (who would have guessed?) that you can add to your worksheet.

Examples:

Creating a chart

# This example creates two charts in a single sheet.
# The first uses data directly fed to the sheet, while the second references cells withing the worksheet for data.

require "rubygems" # if that is your preferred way to manage gems!
require "axlsx"

p = Axlsx::Package.new
ws = p.workbook.add_worksheet
ws.add_row :values => ["This is a chart with no data in the sheet"]

chart = ws.add_chart(Axlsx::Bar3DChart, :start_at=> [0,1], :end_at=>[0,6], :title=>"Most Popular Pets")
chart.add_series :data => [1, 9, 10], :labels => ["Slimy Reptiles", "Fuzzy Bunnies", "Rottweiler"]

ws.add_row :values => ["This chart uses the data below"]
title_row = ws.add_row :values => ["Least Popular Pets"]
label_row = ws.add_row :values => ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"]
data_row = ws.add_row :values => ["Votes", 6, 4, 1]

chart = ws.add_chart(Axlsx::Pie3DChart, :start_at => [0,11], :end_at =>[0,16], :title => title_row.cells.last)
chart.add_series :data => data_row.cells[(1..-1)], :labels => label_row.cells  

f = File.open('example_pie_3d_chart.xlsx', 'w')
p.serialize(f)

See Also:

Constant Summary collapse

GAP_AMOUNT_PERCENT =

validation regex for gap amount percent

/0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/

Instance Attribute Summary collapse

Attributes inherited from Chart

#end_at, #graphic_frame, #index, #pn, #series, #series_type, #show_legend, #start_at, #title, #view3D

Instance Method Summary collapse

Methods inherited from Chart

#add_series

Constructor Details

#initialize(frame, options = {}) ⇒ Bar3DChart

Creates a new bar chart object

Parameters:

  • frame (GraphicFrame)

    The workbook that owns this chart.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • title (Cell, String)
  • show_legend (Boolean)
  • barDir (Symbol)
  • grouping (Symbol)
  • gapWidth (String)
  • gapDepth (String)
  • shape (Symbol)


79
80
81
82
83
84
85
86
87
88
89
# File 'lib/axlsx/drawing/bar_3D_chart.rb', line 79

def initialize(frame, options={})
  super(frame, options)      
  @series_type = BarSeries
  @barDir = :bar
  @grouping = :clustered
  @catAxId = rand(8 ** 8)
  @valAxId = rand(8 ** 8)
  @catAxis = CatAxis.new(@catAxId, @valAxId)
  @valAxis = ValAxis.new(@valAxId, @catAxId)
  @view3D = View3D.new(:rAngAx=>1)
end

Instance Attribute Details

#barDirSymbol

The direction of the bars in the chart must be one of [:bar, :col]

Returns:

  • (Symbol)


47
48
49
# File 'lib/axlsx/drawing/bar_3D_chart.rb', line 47

def barDir
  @barDir
end

#catAxisCatAxis (readonly)

the category axis

Returns:



38
39
40
# File 'lib/axlsx/drawing/bar_3D_chart.rb', line 38

def catAxis
  @catAxis
end

#gapDepthString

space between bar or column clusters, as a percentage of the bar or column width.

Returns:

  • (String)


51
52
53
# File 'lib/axlsx/drawing/bar_3D_chart.rb', line 51

def gapDepth
  @gapDepth
end

#gapWidthString

space between bar or column clusters, as a percentage of the bar or column width.

Returns:

  • (String)


55
56
57
# File 'lib/axlsx/drawing/bar_3D_chart.rb', line 55

def gapWidth
  @gapWidth
end

#groupingSymbol

grouping for a column, line, or area chart. must be one of [:percentStacked, :clustered, :standard, :stacked]

Returns:

  • (Symbol)


60
61
62
# File 'lib/axlsx/drawing/bar_3D_chart.rb', line 60

def grouping
  @grouping
end

#shapeSymbol

The shabe of the bars or columns must be one of [:percentStacked, :clustered, :standard, :stacked]

Returns:

  • (Symbol)


65
66
67
# File 'lib/axlsx/drawing/bar_3D_chart.rb', line 65

def shape
  @shape
end

#valAxisValAxis (readonly)

the category axis

Returns:



42
43
44
# File 'lib/axlsx/drawing/bar_3D_chart.rb', line 42

def valAxis
  @valAxis
end

Instance Method Details

#to_xmlString

Serializes the bar chart

Returns:

  • (String)


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/axlsx/drawing/bar_3D_chart.rb', line 119

def to_xml
  super() do |xml|
    xml.send('c:bar3DChart') {
      xml.send('c:barDir', :val => barDir)
      xml.send('c:grouping', :val=>grouping)
      xml.send('c:varyColors', :val=>1)
      @series.each { |ser| ser.to_xml(xml) }
      xml.send('c:gapWidth', :val=>@gapWidth) unless @gapWidth.nil?
      xml.send('c:gapDepth', :val=>@gapDepth) unless @gapDepth.nil?
      xml.send('c:shape', :val=>@shape) unless @shape.nil?
      xml.send('c:axId', :val=>@catAxId)
      xml.send('c:axId', :val=>@valAxId)
      xml.send('c:axId', :val=>0)
    }
    @catAxis.to_xml(xml)
    @valAxis.to_xml(xml)        
  end
end