1Graph(3) User Contributed Perl Documentation Graph(3)
2
3
4
6 SVG::Graph - Visualize your data in Scalable Vector Graphics (SVG) for‐
7 mat.
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.01 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
86 1. create an SVG::Graph instance
87 2. create an SVG::Graph::Frame instance by calling
88 SVG::Graph::add_frame();
89 3. create an SVG::Graph::Data instance, containing
90 an SVG::Graph::Data::Datum instance for each data point.
91 4. Attach the SVG::Graph::Data instance to your SVG::Graph::Frame
92 using SVG::Graph::Frame::add_data();
93 5. Attach glyphs to the SVG::Graph::Frame instance using
94 SVG::Graph::Frame::add_glyph();
95 6. Call SVG::Graph::draw();
96
97 MULTIPLE DATA SETS
98
99 1. create an SVG::Graph instance
100 2. create an SVG::Graph::Frame instance by calling
101 SVG::Graph::add_frame();
102 3. create an SVG::Graph::Data instance, containing
103 an SVG::Graph::Data::Datum instance for each data point.
104 4. Attach the SVG::Graph::Data instance to your SVG::Graph::Frame
105 using SVG::Graph::Frame::add_data();
106 5. Attach glyphs to the SVG::Graph::Frame instance using
107 SVG::Graph::Frame::add_glyph();
108 6. repeat [2-5] for each additional data set to be added.
109 add_frame() can be called on SVG::Graph to add top-level data
110 sets, or SVG::Graph::Frame to add hierarchical data sets.
111 7. Call SVG::Graph::draw();
112
114 Send an email to the svg-graph-developers list. For more info, visit
115 the project page at http://www.sf.net/projects/svg-graph
116
118 Allen Day, <allenday@ucla.edu>
119 Chris To, <crsto@ucla.edu>
120
122 James Chen, <chenj@seas.ucla.edu>
123 Brian O'Connor, <boconnor@ucla.edu>
124
126 SVG
127
128 new
129
130 Title : new
131 Usage : my $graph = SVG::Graph->new(width=>600,
132 height=>600,
133 margin=>20);
134 Function: creates a new SVG::Graph object
135 Returns : a SVG::Graph object
136 Args : width => the width of the SVG
137 height => the height of the SVG
138 margin => margin for the root frame
139
140 init
141
142 Title : init
143 Usage :
144 Function:
145 Example :
146 Returns :
147 Args :
148
149 width
150
151 Title : width
152 Usage : $obj->width($newval)
153 Function:
154 Example :
155 Returns : value of width (a scalar)
156 Args : on set, new value (a scalar or undef, optional)
157
158 height
159
160 Title : height
161 Usage : $obj->height($newval)
162 Function:
163 Example :
164 Returns : value of height (a scalar)
165 Args : on set, new value (a scalar or undef, optional)
166
167 margin
168
169 Title : margin
170 Usage : $obj->margin($newval)
171 Function:
172 Example :
173 Returns : value of margin (a scalar)
174 Args : on set, new value (a scalar or undef, optional)
175
176 svg
177
178 Title : svg
179 Usage : $obj->svg($newval)
180 Function:
181 Example :
182 Returns : value of svg (a scalar)
183 Args : on set, new value (a scalar or undef, optional)
184
185 add_frame
186
187 Title : add_frame
188 Usage : my $frame = $graph->add_frame
189 Function: adds a Frame to the current Graph
190 Returns : a SVG::Graph::Frame object
191 Args : a hash. usable keys:
192 frame_transform (optional)
193 'top' default orientation
194 'bottom' rotates graph 180 deg (about the center)
195 'right' points top position towards right
196 'left' points top position towards left
197
198 frames
199
200 Title : frames
201 Usage : get/set
202 Function:
203 Example :
204 Returns :
205 Args :
206
207 xoffset
208
209 Title : xoffset
210 Usage : $obj->xoffset($newval)
211 Function:
212 Example :
213 Returns : value of xoffset (a scalar)
214 Args : on set, new value (a scalar or undef, optional)
215
216 yoffset
217
218 Title : yoffset
219 Usage : $obj->yoffset($newval)
220 Function:
221 Example :
222 Returns : value of yoffset (a scalar)
223 Args : on set, new value (a scalar or undef, optional)
224
225 draw
226
227 Title : draw
228 Usage : $graph=>draw
229 Function: depends on child glyph implementations
230 Returns : xmlifyied SVG object
231 Args : none
232
233
234
235perl v5.8.8 2003-11-27 Graph(3)