1SVG::TT::Graph::Line(3)User Contributed Perl DocumentatioSnVG::TT::Graph::Line(3)
2
3
4

NAME

6       SVG::TT::Graph::Line - Create presentation quality SVG line graphs
7       easily
8

SYNOPSIS

10         use SVG::TT::Graph::Line;
11
12         my @fields = qw(Jan Feb Mar);
13         my @data_sales_02 = qw(12 45 21);
14         my @data_sales_03 = qw(15 30 40);
15
16         my $graph = SVG::TT::Graph::Line->new({
17           'height' => '500',
18           'width'  => '300',
19           'fields' => \@fields,
20         });
21
22         $graph->add_data({
23           'data'  => \@data_sales_02,
24           'title' => 'Sales 2002',
25         });
26
27         $graph->add_data({
28           'data' => \@data_sales_03,
29           'title' => 'Sales 2003',
30         });
31
32         print "Content-type: image/svg+xml\n\n";
33         print $graph->burn();
34

DESCRIPTION

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

METHODS

43   new()
44         use SVG::TT::Graph::Line;
45
46         # Field names along the X axis
47         my @fields = qw(Jan Feb Mar);
48
49         my $graph = SVG::TT::Graph::Line->new({
50           # Required
51           'fields'                 => \@fields,
52
53           # Optional - defaults shown
54           'height'                 => '500',
55           'width'                  => '300',
56
57           'show_data_points'       => 1,
58           'show_data_values'       => 1,
59           'stacked'                => 0,
60
61           'min_scale_value'        => '0',
62           'max_scale_value'        => undef,
63           'area_fill'              => 0,
64           'show_x_labels'          => 1,
65           'stagger_x_labels'       => 0,
66           'rotate_x_labels'        => 0,
67           'show_y_labels'          => 1,
68           'scale_integers'         => 0,
69           'scale_divisions'        => '20',
70           'y_label_formatter'      => sub { return @_ },
71           'x_label_formatter'      => sub { return @_ },
72
73           'show_x_title'           => 0,
74           'x_title'                => 'X Field names',
75
76           'show_y_title'           => 0,
77           'y_title_text_direction' => 'bt',
78           'y_title'                => 'Y Scale',
79
80           'show_graph_title'       => 0,
81           'graph_title'            => 'Graph Title',
82           'show_graph_subtitle'    => 0,
83           'graph_subtitle'         => 'Graph Sub Title',
84           'key'                    => 0,
85           'key_position'           => 'right',
86
87           # Stylesheet defaults
88           'style_sheet'             => '/includes/graph.css', # internal stylesheet
89           'random_colors'           => 0,
90         });
91
92       The constructor takes a hash reference, fields (the names for each
93       field on the X axis) MUST be set, all other values are defaulted to
94       those shown above - with the exception of style_sheet which defaults to
95       using the internal style sheet.
96
97   add_data()
98         my @data_sales_02 = qw(12 45 21);
99
100         $graph->add_data({
101           'data' => \@data_sales_02,
102           'title' => 'Sales 2002',
103         });
104
105       This method allows you to add data to the graph object.  It can be
106       called several times to add more data sets in.
107
108   clear_data()
109         my $graph->clear_data();
110
111       This method removes all data from the object so that you can reuse it
112       to create a new graph but with the same config options.
113
114   burn()
115         print $graph->burn();
116
117       This method processes the template with the data and config which has
118       been set and returns the resulting SVG.
119
120       This method will croak unless at least one data set has been added to
121       the graph object.
122
123   config methods
124         my $value = $graph->method();
125         my $confirmed_new_value = $graph->method($value);
126
127       The following is a list of the methods which are available to change
128       the config of the graph object after it has been created.
129
130       height()
131           Set the height of the graph box, this is the total height of the
132           SVG box created - not the graph it self which auto scales to fix
133           the space.
134
135       width()
136           Set the width of the graph box, this is the total height of the SVG
137           box created - not the graph it self which auto scales to fix the
138           space.
139
140       compress()
141           Whether or not to compress the content of the SVG file
142           (Compress::Zlib required).
143
144       tidy()
145           Whether or not to tidy the content of the SVG file (XML::Tidy
146           required).
147
148       style_sheet()
149           Set the path to an external stylesheet, set to '' if you want to
150           revert back to using the defaut internal version.
151
152           The default stylesheet handles up to 12 data sets. All data series
153           over the 12th will have no style and be in black. If you have over
154           12 data sets you can assign them all random colors (see the
155           random_color() method) or create your own stylesheet and add the
156           additional settings for the extra data sets.
157
158           To create an external stylesheet create a graph using the default
159           internal version and copy the stylesheet section to an external
160           file and edit from there.
161
162       random_colors()
163           Use random colors in the internal stylesheet
164
165       show_data_values()
166           Show the value of each element of data on the graph
167
168       show_data_points()
169           Show a small circle on the graph where the line goes from one point
170           to the next.
171
172       stacked()
173           Accumulates each data set. (i.e. Each point increased by sum of all
174           previous series at same point). Default is 0, set to '1' to show.
175
176       min_scale_value()
177           The point at which the Y axis starts, defaults to '0', if set to ''
178           it will default to the minimum data value.
179
180       max_scale_value()
181           The maximum value for the Y axis.  If set to '', it will default to
182           the maximum data value.
183
184       show_x_labels()
185           Whether to show labels on the X axis or not, defaults to 1, set to
186           '0' if you want to turn them off.
187
188       show_y_labels()
189           Whether to show labels on the Y axis or not, defaults to 1, set to
190           '0' if you want to turn them off.
191
192       scale_integers()
193           Ensures only whole numbers are used as the scale divisions.
194           Default it '0', to turn on set to '1'. This has no effect if scale
195           divisions are less than 1.
196
197       scale_divisions()
198           This defines the gap between markers on the Y axis, default is a
199           10th of the max_value, e.g. you will have 10 markers on the Y axis.
200           NOTE: do not set this too low - you are limited to 999 markers,
201           after that the graph won't generate.
202
203       stagger_x_labels()
204           This puts the labels at alternative levels so if they are long
205           field names they will not overlap so easily.  Default it '0', to
206           turn on set to '1'.
207
208       rotate_x_labels()
209           This turns the X axis labels by 90 degrees.  Default it '0', to
210           turn on set to '1'.
211
212       show_x_title()
213           Whether to show the title under the X axis labels, default is 0,
214           set to '1' to show.
215
216       x_title()
217           What the title under X axis should be, e.g. 'Months'.
218
219       show_y_title()
220           Whether to show the title under the Y axis labels, default is 0,
221           set to '1' to show.
222
223       y_title_text_direction()
224           Aligns writing mode for Y axis label. Defaults to 'bt' (Bottom to
225           Top).  Change to 'tb' (Top to Bottom) to reverse.
226
227       y_title()
228           What the title under Y axis should be, e.g. 'Sales in thousands'.
229
230       show_graph_title()
231           Whether to show a title on the graph, default is 0, set to '1' to
232           show.
233
234       graph_title()
235           What the title on the graph should be.
236
237       show_graph_subtitle()
238           Whether to show a subtitle on the graph, default is 0, set to '1'
239           to show.
240
241       graph_subtitle()
242           What the subtitle on the graph should be.
243
244       key()
245           Whether to show a key, defaults to 0, set to '1' if you want to
246           show it.
247
248       key_position()
249           Where the key should be positioned, defaults to 'right', set to
250           'bottom' if you want to move it.
251
252       x_label_formatter ()
253           A callback subroutine which will format a label on the x axis.  For
254           example:
255
256               $graph->x_label_formatter( sub { return '$' . $_[0] } );
257
258       y_label_formatter()
259           A callback subroutine which will format a label on the y axis.  For
260           example:
261
262               $graph->y_label_formatter( sub { return '$' . $_[0] } );
263

EXAMPLES

265       For examples look at the project home page
266       http://leo.cuckoo.org/projects/SVG-TT-Graph/
267

EXPORT

269       None by default.
270

SEE ALSO

272       SVG::TT::Graph, SVG::TT::Graph::Bar, SVG::TT::Graph::BarHorizontal,
273       SVG::TT::Graph::BarLine, SVG::TT::Graph::Pie,
274       SVG::TT::Graph::TimeSeries, SVG::TT::Graph::XY, Compress::Zlib,
275       XML::Tidy
276
277
278
279perl v5.28.0                      2014-09-22           SVG::TT::Graph::Line(3)
Impressum