Class: SVG::Graph::Line Deprecated

Inherits:
Graph
  • Object
show all
Defined in:
lib/SVG/Graph/Line.rb

Overview

Deprecated.

Removed at 4.0.0

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

  • 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

Since:

  • 0.5.0

Instance Attribute Summary collapse

Attributes inherited from Graph

#add_popups, #font_size, #graph_subtitle, #graph_title, #height, #key, #key_font_size, #key_position, #min_scale_value, #no_css, #rotate_x_labels, #rotate_y_labels, #scale_divisions, #scale_integers, #show_data_values, #show_graph_subtitle, #show_graph_title, #show_x_guidelines, #show_x_labels, #show_x_title, #show_y_guidelines, #show_y_labels, #show_y_title, #stagger_x_labels, #stagger_y_labels, #step_include_first_x_label, #step_x_labels, #style_sheet, #subtitle_font_size, #title_font_size, #width, #x_label_font_size, #x_title, #x_title_font_size, #y_label_font_size, #y_title, #y_title_font_size, #y_title_text_direction

Instance Method Summary collapse

Methods inherited from Graph

#add_data, #burn, #clear_data

Constructor Details

#initialize(config) ⇒ Line

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

#area_fillObject

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

#show_data_pointsObject

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

#stackedObject

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

#set_defaultsObject

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