Class SVG::Graph::Bar
In: temp/Graph/Bar.rb
Parent: BarBase

SVG::Graph::Bar

0.2.0

Create presentation quality SVG bar graphs easily

Synopsis

  require 'SVG/Graph/Bar'

  fields = %w(Jan Feb Mar);
  data_sales_02 = %w(12 45 21)
  graph = SVG::Graph::Bar.new({
    :height => 500,
    :width => 300,
    :fields => fields
  })

  graph.add_data({
    :data => data_sales_02,
    :title => 'Sales 2002'
  })
  print "Content-type: image/svg+xml\r\n\r\n"
  print graph.burn

Description

This object aims to allow you to easily create high quality SVG bar graphs. You can either use the default style sheet or supply your own. Either way there are many options which can be configured to give you control over how the graph is generated - with or without a key, data elements at each point, title, subtitle etc.

Copyright 2004 Sean E. Russell

Notes

The default stylesheet handles upto 12 data sets, if you use more you must create your own stylesheet and add the additional settings for the extra data sets. You will know if you go over 12 data sets as they will have no style and be in black.

Examples

Acknowledgements

Leo Lapworth for creating the SVG::TT::Graph package which this Ruby port is based on.

Stephen Morgan for creating the TT template and SVG.

Author

Sean E. Russell <serATgermaneHYPHENsoftwareDOTcom>

See also

Methods
draw_data    get_x_labels    get_y_labels    new    top_align    top_font    x_label_offset   
Included modules
REXML
Public Class methods
new(config)

The constructor takes a hash reference, fields (the names for each field on the X axis) MUST be set, all other values are defaulted to those shown above - with the exception of style_sheet which defaults to using the internal style sheet.

   require 'SVG/Graph/Bar'

   # Field names along the X axis
   fields = %w(Jan Feb Mar)
   graph = SVG::Graph::Bar.new({
      # Required
      :fields => fields,

      # Optional - defaults shown
      :height            => 500,
      :width             => 300,
      :show_data_values  => true,
      :min_scale_value   => 0,
      :stagger_x_labels  => false,
      :rotate_x_labels   => false,
      :bar_gap           => true,

      :show_x_labels     => true,
      :show_y_labels     => true,
      :scale_integers    => false,
      :scale_divisions   => 0,
      :show_x_title      => false,
      :x_title           => 'X Field names',

      :show_y_title      => false,
      :y_title_text_direction => :bt,
      :y_title           => 'Y Scale',
      :show_graph_title  => false,
      :graph_title       => 'Graph Title',
      :show_graph_subtitle   => false,
      :graph_subtitle        => 'Graph Sub Title',

      :key                   => false,
      :key_position          => :right,
      # Optional - defaults to using internal stylesheet
      :style_sheet       => '/includes/graph.css'
   })
Public Instance methods
get_x_labels()
get_y_labels()
x_label_offset( width )
top_align()
This method is also aliased as top_font
top_font()

Alias for top_align

draw_data()