Wednesday, July 7, 2010

Ruby :: Pie :: SVG :: Graph

Download SVG from http://www.germane-software.com/software/SVG/SVG::Graph/

Place the SVG folder in the current folder
=====
require 'SVG/Graph/Pie'

fields = %w(Staphylococcus Corynebacterium Acinetobacter Propionibacterium Rothia Pseudomonas Leptotrichia Herbaspirillum Stenotrophomonas Streptococcus)

dataVal = [0.46494, 0.43779, 0.02067, 0.01934, 0.01081, 0.00155, 0.00109, 0.00105, 0.00027, 0.00014]

graph = SVG::Graph::Pie.new({:height => 400, :width => 800, :fields => fields })
graph.add_data({
    :data => dataVal,
    :title => 'TITLE',
})

graph.expanded = false
graph.expand_gap = 3
graph.show_data_labels = true
graph.show_key_data_labels = true
graph.show_percent = true
graph.show_shadow = false
graph.datapoint_font_size = 40

output = File.open('test1.svg', "w+")
output.write graph.burn()
output.close
=================================

The file should be written










Another method is to 
 $ sudo gem install gruff

No comments:

Post a Comment