Skip to content

Instantly share code, notes, and snippets.

@preetika-subramaniam
Forked from manusajith/axlsx_bar_graph.rb
Created January 27, 2018 05:01
Show Gist options
  • Select an option

  • Save preetika-subramaniam/74632f5a97ebab1c60e93452aef91cce to your computer and use it in GitHub Desktop.

Select an option

Save preetika-subramaniam/74632f5a97ebab1c60e93452aef91cce to your computer and use it in GitHub Desktop.
Create a simple Bar Graph in excel in ruby using axlsx gem
require 'axlsx'
Axlsx::Package.new do |p|
p.workbook.add_worksheet(:name => "Pie Chart") do |sheet|
sheet.add_row ["Simple Pie Chart"]
%w(first second third).each { |label| sheet.add_row [label, rand(24)+1] }
sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A6", :end_at => "F20", :barDir => :col) do |chart|
chart.add_series :data => sheet["B2:B4"], :labels => sheet["A2:A4"], :colors => ['FF0000', '00FF00', '0000FF']
end
end
p.serialize('simple.xlsx')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment