Class SVG::Graph::Line
In: temp/Graph/Line.rb
Parent: SVG::Graph::Graph

Create presentation quality SVG line graphs easily

Synopsis

  require 'SVG/Graph/Line'

  fields = %w(Jan Feb Mar);
  data_sales_02 = [12, 45, 21]
  data_sales_03 = [15, 30, 40]

  graph = SVG::Graph::Line.new({
          :height => 500,
          :width => 300,
    :fields => fields,
  })

  graph.add_data({
          :data => data_sales_02,
    :title => 'Sales 2002',
  })

  graph.add_data({
          :data => data_sales_03,
    :title => 'Sales 2003',
  })

  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 line 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.

Examples

www.germane-software/repositories/public/SVG/test/single.rb

Notes

The default stylesheet handles upto 10 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 10 data sets as they will have no style and be in black.

See also

Author

Sean E. Russell <serATgermaneHYPHENsoftwareDOTcom>

Copyright 2004 Sean E. Russell This software is available under the Ruby license

Methods

Attributes

area_fill  [RW]  Fill in the area under the plot if true
show_data_points  [RW]  Show a small circle on the graph where the line goes from one point to the next.
stacked  [RW] 
 Accumulates each data set. (i.e. Each point increased by sum of
all previous series at same point). Default is 0, set to ‘1’ to show.

Public Class methods

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.

Public Instance methods

In addition to the defaults set in Graph::initialize, sets

show_data_points
true
show_data_values
true
stacked
false
area_fill
false

Protected Instance methods

[Validate]