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           Set to "inline:<style>...</style>" with your CSS in between the
158           tags.  You can thus override the default style without requireing
159           an external URL.
160
161           The default stylesheet handles up to 12 data sets. All data series
162           over the 12th will have no style and be in black. If you have over
163           12 data sets you can assign them all random colors (see the
164           random_color() method) or create your own stylesheet and add the
165           additional settings for the extra data sets.
166
167           To create an external stylesheet create a graph using the default
168           internal version and copy the stylesheet section to an external
169           file and edit from there.
170
171       random_colors()
172           Use random colors in the internal stylesheet.
173
174       show_data_values()
175           Show the value of each element of data on the graph (or optionally
176           a user-defined label; see add_data).
177
178       show_data_points()
179           Show a small circle on the graph where the line goes from one point
180           to the next.
181
182       rollover_values()
183           Shows data values and data points when the mouse is over the point.
184           Used in combination with show_data_values and/or show_data_points.
185
186       data_value_format()
187           Format specifier to for data values (as per printf).
188
189       max_x_span()
190           Maximum span for a line between data points on the X-axis. If this
191           span is exceeded, the points are not connected. This is useful for
192           skipping missing data sections. If you set this value to something
193           smaller than 0 (e.g. -1), you will get an XY scatter plot with no
194           line joining the data points.
195
196       stacked()
197           Accumulates each data set. (i.e. Each point increased by sum of all
198           previous series at same point). Default is 0, set to '1' to show.
199
200       min_yscale_value()
201           The point at which the Y axis starts, defaults to '0', if set to ''
202           it will default to the minimum data value.
203
204       max_yscale_value()
205           The point at which the Y axis ends, if set to '' it will default to
206           the maximum data value.
207
208       yscale_divisions()
209           This defines the gap between markers on the Y axis, default is a
210           10th of the range, e.g. you will have 10 markers on the Y axis.
211           NOTE: do not set this too low - you are limited to 999 markers,
212           after that the graph won't generate.
213
214       show_x_labels()
215           Whether to show labels on the X axis or not, defaults to 1, set to
216           '0' if you want to turn them off.
217
218       show_y_labels()
219           Whether to show labels on the Y axis or not, defaults to 1, set to
220           '0' if you want to turn them off.
221
222       y_label_format()
223           Format string for presenting the Y axis labels (as per printf).
224
225       xscale_divisions()
226           This defines the gap between markers on the X axis.  Default is the
227           entire range (only start and end axis labels).
228
229       stagger_x_labels()
230           This puts the labels at alternative levels so if they are long
231           field names they will not overlap so easily.  Default it '0', to
232           turn on set to '1'.
233
234       rotate_x_labels()
235           This turns the X axis labels by 90 degrees.  Default it '0', to
236           turn on set to '1'.
237
238       min_xscale_value()
239           This sets the minimum X value. Any data points before this value
240           will not be shown.
241
242       max_xscale_value()
243           This sets the maximum X value. Any data points after this value
244           will not be shown.
245
246       show_x_title()
247           Whether to show the title under the X axis labels, default is 0,
248           set to '1' to show.
249
250       x_title()
251           What the title under X axis should be, e.g. 'Parameter X'.
252
253       show_y_title()
254           Whether to show the title under the Y axis labels, default is 0,
255           set to '1' to show.
256
257       y_title()
258           What the title under Y axis should be, e.g. 'Sales in thousands'.
259
260       show_graph_title()
261           Whether to show a title on the graph, default is 0, set to '1' to
262           show.
263
264       graph_title()
265           What the title on the graph should be.
266
267       show_graph_subtitle()
268           Whether to show a subtitle on the graph, default is 0, set to '1'
269           to show.
270
271       graph_subtitle()
272           What the subtitle on the graph should be.
273
274       key()
275           Whether to show a key, defaults to 0, set to '1' if you want to
276           show it.
277
278       key_position()
279           Where the key should be positioned, defaults to 'right', set to
280           'bottom' if you want to move it.
281
282       x_label_formatter ()
283           A callback subroutine which will format a label on the x axis.  For
284           example:
285
286               $graph->x_label_formatter( sub { return '$' . $_[0] } );
287
288       y_label_formatter()
289           A callback subroutine which will format a label on the y axis.  For
290           example:
291
292               $graph->y_label_formatter( sub { return '$' . $_[0] } );
293

EXAMPLES

295       For examples look at the project home page
296       http://leo.cuckoo.org/projects/SVG-TT-Graph/
297

EXPORT

299       None by default.
300

SEE ALSO

302       SVG::TT::Graph, SVG::TT::Graph::Line, SVG::TT::Graph::Bar,
303       SVG::TT::Graph::BarHorizontal, SVG::TT::Graph::BarLine,
304       SVG::TT::Graph::Pie, Compress::Zlib, XML::Tidy
305
306
307
308perl v5.32.0                      2020-07-28             SVG::TT::Graph::XY(3)
Impressum