From 158942c16b249a269e77633dd261b87787d191af Mon Sep 17 00:00:00 2001 From: Zsolt Kozaroczy Date: Sat, 24 Jul 2021 00:31:54 +0200 Subject: Add overlap to bar charts (#107) --- examples/README.md | 1 + examples/images/stacked_bar_chart_example.png | Bin 0 -> 28959 bytes examples/stacked_bar_chart_example.md | 35 ++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 examples/images/stacked_bar_chart_example.png create mode 100644 examples/stacked_bar_chart_example.md (limited to 'examples') diff --git a/examples/README.md b/examples/README.md index eca725dc..5f53199e 100644 --- a/examples/README.md +++ b/examples/README.md @@ -44,6 +44,7 @@ Types: * [Line chart (3D)](3d_line_chart_example.md) * [Pie chart (3D)](3d_pie_chart_example.md) * [Scatter chart](scatter_chart_example.md) +* [Stacked bar chart](stacked_bar_chart_example.md) Customizations: * [Chart colors](chart_colors_example.md) diff --git a/examples/images/stacked_bar_chart_example.png b/examples/images/stacked_bar_chart_example.png new file mode 100644 index 00000000..da046983 Binary files /dev/null and b/examples/images/stacked_bar_chart_example.png differ diff --git a/examples/stacked_bar_chart_example.md b/examples/stacked_bar_chart_example.md new file mode 100644 index 00000000..3fbd2425 --- /dev/null +++ b/examples/stacked_bar_chart_example.md @@ -0,0 +1,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") -- cgit v1.2.3