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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
# require 'SVG/Graph/Pie'
title = "Pie"
#data1 = []
#(rand(10)+5).times{
# data1 << rand(20)
# data1 << rand(20)
#}
data1 = [3, 11.2, 2.2, 5.4, 18.5, 7.6, 3, 2.2,]
#data2 = []
#(rand(10)+5).times{
# data2 << rand(20)
# data2 << rand(20)
#}
data2 = [4, 18, 3, 7, 8, 13, 19, 1,]
#data1 = [3]
#data2 = [2]
field = %w{jan feb mar apr may jun jul aug}
g = SVG::Graph::Pie.new( {
:width => 640,
:height => 300,
:graph_title => title,
:show_graph_title => true,
:key => true,
:key_position => :right, #:bottom, # or :right
:fields => field,
:show_data_labels => true,
:show_actual_values => true,
:show_shadow => true,
:expanded => false,
:expand_greatest => true
})
g.add_data(
:data => data1,
:title => "Dataset 1"
)
g.add_data(
:data => data2,
:title => "Dataset 2"
)
#puts graph.burn
output_filename = File.basename(__FILE__, ".rb")
if defined?(USE_FOR_TESTING)
File.open(File.join(OUTPUT_FOLDER, "#{output_filename}.html"), "w") {|f| f.write(g.burn)}
else
File.open(File.expand_path("#{output_filename}.svg",__dir__), 'w') {|f| f.write(g.burn_svg_only)} # for inclusion into readme.md
end
|