summaryrefslogtreecommitdiffhomepage
path: root/examples/stacked_bar_chart_example.md
blob: 3fbd242593225b8e33a19e4ad95c6ca7b3d6b841 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
## Description

Stacked bar chart example

## Code

```ruby
require 'axlsx'

p = Axlsx::Package.new
wb = p.workbook

wb.add_worksheet(name: 'Bar Chart') do |sheet|
  sheet.add_row ['A Simple Bar Chart', 'X', 'Y']

  sheet.add_row ['A', 3, 4]
  sheet.add_row ['B', 10, 6]
  sheet.add_row ['C', 7, 2]

  sheet.add_chart(Axlsx::BarChart, start_at: 'A6', end_at: 'F20') do |chart|
    chart.add_series data: sheet['B2:B4'], labels: sheet['A2:A4'], title: sheet['B1']
    chart.add_series data: sheet['C2:C4'], labels: sheet['A2:A4'], title: sheet['C1']

    chart.bar_dir = :col
    chart.overlap = 100
    chart.grouping = :percentStacked
  end
end

p.serialize 'stacked_bar_chart_example.xlsx'
```

## Output

![Output](images/stacked_bar_chart_example.png "Output")