1Graph(3) User Contributed Perl Documentation Graph(3)
2
3
4
6 SVG::Graph - Visualize your data in Scalable Vector Graphics (SVG)
7 format.
8
10 use SVG::Graph;
11 use SVG::Graph::Data;
12 use SVG::Graph::Data::Datum;
13
14 #create a new SVG document to plot in...
15 my $graph = SVG::Graph->new(width=>600,height=>600,margin=>30);
16
17 #and create a frame to hold the data/glyphs
18 my $frame = $graph->add_frame;
19
20 #let's plot y = x^2
21 my @data = map {SVG::Graph::Data::Datum->new(x=>$_,y=>$_^2)}
22 (1,2,3,4,5);
23 my $data = SVG::Graph::Data->new(data => \@data);
24
25 #put the xy data into the frame
26 $frame->add_data($data);
27
28 #add some glyphs to apply to the data in the frame
29 $frame->add_glyph('axis', #add an axis glyph
30 'x_absolute_ticks' => 1, #with ticks every one
31 #unit on the x axis
32 'y_absolute_ticks' => 1, #and ticks every one
33 #unit on the y axis
34
35 'stroke' => 'black', #draw the axis black
36 'stroke-width' => 2, #and 2px thick
37 );
38
39 $frame->add_glyph('scatter', #add a scatterplot glyph
40 'stroke' => 'red', #the dots will be outlined
41 #in red,
42 'fill' => 'red', #filled red,
43 'fill-opacity' => 0.5, #and 50% opaque
44 );
45
46 #print the graphic
47 print $graph->draw;
48
50 SVG::Graph is a suite of perl modules for plotting data. SVG::Graph
51 currently supports plots of one-, two- and three-dimensional data, as
52 well as N-ary rooted trees. Data may be represented as:
53
54 Glyph Name Dimensionality supported
55 1d 2d 3d tree
56 --------------------------------------------------------
57 Axis x
58 Bar Graph x
59 Bubble Plot x
60 Heatmap Graph x
61 Line Graph x
62 Pie Graph x
63 Scatter Plot x
64 Spline Graph x
65 Tree x
66
67 SVG::Graph 0.02 is a pre-alpha release. Keep in mind that many of the
68 glyphs are not very robust.
69
71 You need to create a SVG::Graph::Frame instance from the parent
72 SVG::Graph instance for each set of data to be plotted. Datasets can
73 be hierarchical, and to represent this, SVG::Graph::Frame instances can
74 themselves contain subframes. SVG::Graph::Frame can contain:
75
76 - multiple subframes as instances of SVG::Graph::Frame
77 - a single SVG::Graph::Data instance
78 - multiple SVG::Graph::Glyph instances with which to render
79 the attached SVG::Graph::Data instance, and all SVG::Graph::Data
80 instances attached to SVG::Graph::Frame subinstances
81
82 See SVG::Graph::Frame and SVG::Graph::Glyph for details.
83
84 ONE DATA SET
85 1. create an SVG::Graph instance
86 2. create an SVG::Graph::Frame instance by calling
87 SVG::Graph::add_frame();
88 3. create an SVG::Graph::Data instance, containing
89 an SVG::Graph::Data::Datum instance for each data point.
90 4. Attach the SVG::Graph::Data instance to your SVG::Graph::Frame
91 using SVG::Graph::Frame::add_data();
92 5. Attach glyphs to the SVG::Graph::Frame instance using
93 SVG::Graph::Frame::add_glyph();
94 6. Call SVG::Graph::draw();
95
96 MULTIPLE DATA SETS
97 1. create an SVG::Graph instance
98 2. create an SVG::Graph::Frame instance by calling
99 SVG::Graph::add_frame();
100 3. create an SVG::Graph::Data instance, containing
101 an SVG::Graph::Data::Datum instance for each data point.
102 4. Attach the SVG::Graph::Data instance to your SVG::Graph::Frame
103 using SVG::Graph::Frame::add_data();
104 5. Attach glyphs to the SVG::Graph::Frame instance using
105 SVG::Graph::Frame::add_glyph();
106 6. repeat [2-5] for each additional data set to be added.
107 add_frame() can be called on SVG::Graph to add top-level data
108 sets, or SVG::Graph::Frame to add hierarchical data sets.
109 7. Call SVG::Graph::draw();
110
112 Send an email to the svg-graph-developers list. For more info, visit
113 the project page at http://www.sf.net/projects/svg-graph
114
116 Allen Day, <allenday@ucla.edu>
117 Chris To, <crsto@ucla.edu>
118
120 James Chen, <chenj@seas.ucla.edu>
121 Brian O'Connor, <boconnor@ucla.edu>
122
124 SVG
125
126 new
127 Title : new
128 Usage : my $graph = SVG::Graph->new(width=>600,
129 height=>600,
130 margin=>20);
131 Function: creates a new SVG::Graph object
132 Returns : a SVG::Graph object
133 Args : width => the width of the SVG
134 height => the height of the SVG
135 margin => margin for the root frame
136
137 init
138 Title : init
139 Usage :
140 Function:
141 Example :
142 Returns :
143 Args :
144
145 width
146 Title : width
147 Usage : $obj->width($newval)
148 Function:
149 Example :
150 Returns : value of width (a scalar)
151 Args : on set, new value (a scalar or undef, optional)
152
153 height
154 Title : height
155 Usage : $obj->height($newval)
156 Function:
157 Example :
158 Returns : value of height (a scalar)
159 Args : on set, new value (a scalar or undef, optional)
160
161 margin
162 Title : margin
163 Usage : $obj->margin($newval)
164 Function:
165 Example :
166 Returns : value of margin (a scalar)
167 Args : on set, new value (a scalar or undef, optional)
168
169 svg
170 Title : svg
171 Usage : $obj->svg($newval)
172 Function:
173 Example :
174 Returns : value of svg (a scalar)
175 Args : on set, new value (a scalar or undef, optional)
176
177 add_frame
178 Title : add_frame
179 Usage : my $frame = $graph->add_frame
180 Function: adds a Frame to the current Graph
181 Returns : a SVG::Graph::Frame object
182 Args : a hash. usable keys:
183 frame_transform (optional)
184 'top' default orientation
185 'bottom' rotates graph 180 deg (about the center)
186 'right' points top position towards right
187 'left' points top position towards left
188
189 frames
190 Title : frames
191 Usage : get/set
192 Function:
193 Example :
194 Returns :
195 Args :
196
197 xoffset
198 Title : xoffset
199 Usage : $obj->xoffset($newval)
200 Function:
201 Example :
202 Returns : value of xoffset (a scalar)
203 Args : on set, new value (a scalar or undef, optional)
204
205 yoffset
206 Title : yoffset
207 Usage : $obj->yoffset($newval)
208 Function:
209 Example :
210 Returns : value of yoffset (a scalar)
211 Args : on set, new value (a scalar or undef, optional)
212
213 draw
214 Title : draw
215 Usage : $graph=>draw
216 Function: depends on child glyph implementations
217 Returns : xmlifyied SVG object
218 Args : none
219
220
221
222perl v5.12.0 2008-06-11 Graph(3)