Class: SVG::Graph::Line
- Inherits:
- show all
- Defined in:
- lib/SVG/Graph/Line.rb
Overview
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
http://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
- SVG::Graph::Graph
- SVG::Graph::BarHorizontal
- SVG::Graph::Bar
- SVG::Graph::Pie
- SVG::Graph::Plot
- SVG::Graph::TimeSeries
Author
Sean E. Russell <serATgermaneHYPHENsoftwareDOTcom>
Copyright 2004 Sean E. Russell This software is available under the Ruby license[LICENSE.txt]
Constant Summary
Constants included from
Instance Attribute Summary
-
- (Object) area_fill
Fill in the area under the plot if true.
-
- (Object) show_data_points
Show a small circle on the graph where the line.
-
- (Object) stacked
Accumulates each data set.
Instance Method Summary
-
- (Line) initialize(config)
constructor
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.
-
- (Object) set_defaults
In addition to the defaults set in Graph::initialize, sets
- show_data_points
- true
- show_data_values
- true
- stacked
- false
- area_fill
- false.
Constructor Details
- (Line) initialize(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.
85 86 87 88 89 90 |
# File 'lib/SVG/Graph/Line.rb', line 85 def initialize config raise "fields was not supplied or is empty" unless config[:fields] && config[:fields].kind_of?(Array) && config[:fields].length > 0 super end |
Instance Attribute Details
- (Object) area_fill
Fill in the area under the plot if true
79 80 81 |
# File 'lib/SVG/Graph/Line.rb', line 79 def area_fill @area_fill end |
- (Object) show_data_points
Show a small circle on the graph where the line
goes from one point to the next.
74 75 76 |
# File 'lib/SVG/Graph/Line.rb', line 74 def show_data_points @show_data_points end |
- (Object) stacked
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.
77 78 79 |
# File 'lib/SVG/Graph/Line.rb', line 77 def stacked @stacked end |
Instance Method Details
- (Object) set_defaults
In addition to the defaults set in Graph::initialize, sets
- show_data_points
- true
- show_data_values
- true
- stacked
- false
- area_fill
- false
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/SVG/Graph/Line.rb', line 97 def set_defaults init_with( :show_data_points => true, :show_data_values => true, :stacked => false, :area_fill => false ) self.top_align = self.top_font = self.right_align = self.right_font = 1 end |