1SVG::TT::Graph::XY(3) User Contributed Perl DocumentationSVG::TT::Graph::XY(3)
2
3
4

NAME

6       SVG::TT::Graph::XY - Create presentation quality SVG line graphs of XY
7       data points easily
8

SYNOPSIS

10         use SVG::TT::Graph::XY;
11
12         my @data_cpu  = (0.3, 23, 0.5, 54, 1.0, 67, 1.8, 12);
13         my @data_disk = (0.45, 12, 0.51, 26, 0.53, 23);
14
15         my $graph = SVG::TT::Graph::XY->new({
16           'height' => '500',
17           'width'  => '300',
18         });
19
20         $graph->add_data({
21           'data'  => \@data_cpu,
22           'title' => 'CPU',
23         });
24
25         $graph->add_data({
26           'data'  => \@data_disk,
27           'title' => 'Disk',
28         });
29
30         print "Content-type: image/svg+xml\n\n";
31         print $graph->burn();
32

DESCRIPTION

34       This object aims to allow you to easily create high quality SVG line
35       graphs of XY data. You can either use the default style sheet or supply
36       your own. Either way there are many options which can be configured to
37       give you control over how the graph is generated - with or without a
38       key, data elements at each point, title, subtitle etc.
39

METHODS

41   new()
42         use SVG::TT::Graph::XY;
43
44         my $graph = SVG::TT::Graph::XY->new({
45
46           # Optional - defaults shown
47           'height'              => 500,
48           'width'               => 300,
49
50           'show_y_labels'       => 1,
51           'yscale_divisions'    => '',
52           'min_yscale_value'    => 0,
53           'max_yscale_value'    => '',
54
55           'show_x_labels'       => 1,
56           'xscale_divisions'    => '',
57           'min_xscale_value'    => '',
58           'max_xscale_value'    => '',
59           'stagger_x_labels'    => 0,
60           'rotate_x_labels'     => 0,
61           'y_label_formatter'   => sub { return @_ },
62           'x_label_formatter'   => sub { return @_ },
63
64           'show_data_points'    => 1,
65           'show_data_values'    => 1,
66           'rollover_values'     => 0,
67
68           'area_fill'           => 0,
69
70           'show_x_title'        => 0,
71           'x_title'             => 'X Field names',
72
73           'show_y_title'        => 0,
74           'y_title'             => 'Y Scale',
75
76           'show_graph_title'    => 0,
77           'graph_title'         => 'Graph Title',
78           'show_graph_subtitle' => 0,
79           'graph_subtitle'      => 'Graph Sub Title',
80           'key'                 => 0,
81           'key_position'        => 'right',
82
83           # Stylesheet defaults
84           'style_sheet'         => '/includes/graph.css', # internal stylesheet
85           'random_colors'       => 0,
86         });
87
88       The constructor takes a hash reference with values defaulted to those
89       shown above - with the exception of style_sheet which defaults to using
90       the internal style sheet.
91
92   add_data()
93         my @data_cpu  = (0.3, 23, 0.5, 54, 1.0, 67, 1.8, 12);
94         or
95         my @data_cpu = ([0.3,23], [0.5,54], [1.0,67], [1.8,12]);
96         or
97         my @data_cpu = ([0.3,23,'23%'], [0.5,54,'54%'], [1.0,67,'67%'], [1.8,12,'12%']);
98
99         $graph->add_data({
100           'data' => \@data_cpu,
101           'title' => 'CPU',
102         });
103
104       This method allows you to add data to the graph object.  The data are
105       expected to be either a list of scalars (in which case pairs of
106       elements are taken to be X,Y pairs) or a list of array references.  In
107       the latter case, the first two elements in each referenced array are
108       taken to be X and Y, and the optional third element (if present) is
109       used as the text to display for that point for show_data_values and
110       rollover_values; otherwise the Y value itself is displayed.  It can be
111       called several times to add more data sets in.
112
113   clear_data()
114         my $graph->clear_data();
115
116       This method removes all data from the object so that you can reuse it
117       to create a new graph but with the same config options.
118
119   burn()
120         print $graph->burn();
121
122       This method processes the template with the data and config which has
123       been set and returns the resulting SVG.
124
125       This method will croak unless at least one data set has been added to
126       the graph object.
127
128   config methods
129         my $value = $graph->method();
130         my $confirmed_new_value = $graph->method($value);
131
132       The following is a list of the methods which are available to change
133       the config of the graph object after it has been created.
134
135       height()
136           Set the height of the graph box, this is the total height of the
137           SVG box created - not the graph it self which auto scales to fix
138           the space.
139
140       width()
141           Set the width of the graph box, this is the total width of the SVG
142           box created - not the graph it self which auto scales to fix the
143           space.
144
145       compress()
146           Whether or not to compress the content of the SVG file
147           (Compress::Zlib required).
148
149       tidy()
150           Whether or not to tidy the content of the SVG file (XML::Tidy
151           required).
152
153       style_sheet()
154           Set the path to an external stylesheet, set to '' if you want to
155           revert back to using the default internal version.
156
157           The default stylesheet handles up to 12 data sets. All data series
158           over the 12th will have no style and be in black. If you have over
159           12 data sets you can assign them all random colors (see the
160           random_color() method) or create your own stylesheet and add the
161           additional settings for the extra data sets.
162
163           To create an external stylesheet create a graph using the default
164           internal version and copy the stylesheet section to an external
165           file and edit from there.
166
167       random_colors()
168           Use random colors in the internal stylesheet.
169
170       show_data_values()
171           Show the value of each element of data on the graph (or optionally
172           a user-defined label; see add_data).
173
174       show_data_points()
175           Show a small circle on the graph where the line goes from one point
176           to the next.
177
178       rollover_values()
179           Shows data values and data points when the mouse is over the point.
180           Used in combination with show_data_values and/or show_data_points.
181
182       data_value_format()
183           Format specifier to for data values (as per printf).
184
185       max_x_span()
186           Maximum span for a line between data points on the X-axis. If this
187           span is exceeded, the points are not connected. This is useful for
188           skipping missing data sections. If you set this value to something
189           smaller than 0 (e.g. -1), you will get an XY scatter plot with no
190           line joining the data points.
191
192       stacked()
193           Accumulates each data set. (i.e. Each point increased by sum of all
194           previous series at same point). Default is 0, set to '1' to show.
195
196       min_yscale_value()
197           The point at which the Y axis starts, defaults to '0', if set to ''
198           it will default to the minimum data value.
199
200       max_yscale_value()
201           The point at which the Y axis ends, if set to '' it will default to
202           the maximum data value.
203
204       yscale_divisions()
205           This defines the gap between markers on the Y axis, default is a
206           10th of the range, e.g. you will have 10 markers on the Y axis.
207           NOTE: do not set this too low - you are limited to 999 markers,
208           after that the graph won't generate.
209
210       show_x_labels()
211           Whether to show labels on the X axis or not, defaults to 1, set to
212           '0' if you want to turn them off.
213
214       show_y_labels()
215           Whether to show labels on the Y axis or not, defaults to 1, set to
216           '0' if you want to turn them off.
217
218       y_label_format()
219           Format string for presenting the Y axis labels (as per printf).
220
221       xscale_divisions()
222           This defines the gap between markers on the X axis.  Default is the
223           entire range (only start and end axis labels).
224
225       stagger_x_labels()
226           This puts the labels at alternative levels so if they are long
227           field names they will not overlap so easily.  Default it '0', to
228           turn on set to '1'.
229
230       rotate_x_labels()
231           This turns the X axis labels by 90 degrees.  Default it '0', to
232           turn on set to '1'.
233
234       min_xscale_value()
235           This sets the minimum X value. Any data points before this value
236           will not be shown.
237
238       max_xscale_value()
239           This sets the maximum X value. Any data points after this value
240           will not be shown.
241
242       show_x_title()
243           Whether to show the title under the X axis labels, default is 0,
244           set to '1' to show.
245
246       x_title()
247           What the title under X axis should be, e.g. 'Parameter X'.
248
249       show_y_title()
250           Whether to show the title under the Y axis labels, default is 0,
251           set to '1' to show.
252
253       y_title()
254           What the title under Y axis should be, e.g. 'Sales in thousands'.
255
256       show_graph_title()
257           Whether to show a title on the graph, default is 0, set to '1' to
258           show.
259
260       graph_title()
261           What the title on the graph should be.
262
263       show_graph_subtitle()
264           Whether to show a subtitle on the graph, default is 0, set to '1'
265           to show.
266
267       graph_subtitle()
268           What the subtitle on the graph should be.
269
270       key()
271           Whether to show a key, defaults to 0, set to '1' if you want to
272           show it.
273
274       key_position()
275           Where the key should be positioned, defaults to 'right', set to
276           'bottom' if you want to move it.
277
278       x_label_formatter ()
279           A callback subroutine which will format a label on the x axis.  For
280           example:
281
282               $graph->x_label_formatter( sub { return '$' . $_[0] } );
283
284       y_label_formatter()
285           A callback subroutine which will format a label on the y axis.  For
286           example:
287
288               $graph->y_label_formatter( sub { return '$' . $_[0] } );
289

EXAMPLES

291       For examples look at the project home page
292       http://leo.cuckoo.org/projects/SVG-TT-Graph/
293

EXPORT

295       None by default.
296

SEE ALSO

298       SVG::TT::Graph, SVG::TT::Graph::Line, SVG::TT::Graph::Bar,
299       SVG::TT::Graph::BarHorizontal, SVG::TT::Graph::BarLine,
300       SVG::TT::Graph::Pie, Compress::Zlib, XML::Tidy
301
302
303
304perl v5.28.1                      2014-09-22             SVG::TT::Graph::XY(3)
Impressum