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           Set to "inline:<style>...</style>" with your CSS in between the
153           tags.  You can thus override the default style without requireing
154           an external URL.
155
156           The default stylesheet handles up to 12 data sets. All data series
157           over the 12th will have no style and be in black. If you have over
158           12 data sets you can assign them all random colors (see the
159           random_color() method) or create your own stylesheet and add the
160           additional settings for the extra data sets.
161
162           To create an external stylesheet create a graph using the default
163           internal version and copy the stylesheet section to an external
164           file and edit from there.
165
166       random_colors()
167           Use random colors in the internal stylesheet
168
169       show_data_values()
170           Show the value of each element of data on the graph
171
172       show_data_points()
173           Show a small circle on the graph where the line goes from one point
174           to the next.
175
176       stacked()
177           Accumulates each data set. (i.e. Each point increased by sum of all
178           previous series at same point). Default is 0, set to '1' to show.
179
180       min_scale_value()
181           The point at which the Y axis starts, defaults to '0', if set to ''
182           it will default to the minimum data value.
183
184       max_scale_value()
185           The maximum value for the Y axis.  If set to '', it will default to
186           the maximum data value.
187
188       show_x_labels()
189           Whether to show labels on the X axis or not, defaults to 1, set to
190           '0' if you want to turn them off.
191
192       show_y_labels()
193           Whether to show labels on the Y axis or not, defaults to 1, set to
194           '0' if you want to turn them off.
195
196       scale_integers()
197           Ensures only whole numbers are used as the scale divisions.
198           Default it '0', to turn on set to '1'. This has no effect if scale
199           divisions are less than 1.
200
201       scale_divisions()
202           This defines the gap between markers on the Y axis, default is a
203           10th of the max_value, e.g. you will have 10 markers on the Y axis.
204           NOTE: do not set this too low - you are limited to 999 markers,
205           after that the graph won't generate.
206
207       stagger_x_labels()
208           This puts the labels at alternative levels so if they are long
209           field names they will not overlap so easily.  Default it '0', to
210           turn on set to '1'.
211
212       rotate_x_labels()
213           This turns the X axis labels by 90 degrees.  Default it '0', to
214           turn on set to '1'.
215
216       show_x_title()
217           Whether to show the title under the X axis labels, default is 0,
218           set to '1' to show.
219
220       x_title()
221           What the title under X axis should be, e.g. 'Months'.
222
223       show_y_title()
224           Whether to show the title under the Y axis labels, default is 0,
225           set to '1' to show.
226
227       y_title_text_direction()
228           Aligns writing mode for Y axis label. Defaults to 'bt' (Bottom to
229           Top).  Change to 'tb' (Top to Bottom) to reverse.
230
231       y_title()
232           What the title under Y axis should be, e.g. 'Sales in thousands'.
233
234       show_graph_title()
235           Whether to show a title on the graph, default is 0, set to '1' to
236           show.
237
238       graph_title()
239           What the title on the graph should be.
240
241       show_graph_subtitle()
242           Whether to show a subtitle on the graph, default is 0, set to '1'
243           to show.
244
245       graph_subtitle()
246           What the subtitle on the graph should be.
247
248       key()
249           Whether to show a key, defaults to 0, set to '1' if you want to
250           show it.
251
252       key_position()
253           Where the key should be positioned, defaults to 'right', set to
254           'bottom' if you want to move it.
255
256       x_label_formatter ()
257           A callback subroutine which will format a label on the x axis.  For
258           example:
259
260               $graph->x_label_formatter( sub { return '$' . $_[0] } );
261
262       y_label_formatter()
263           A callback subroutine which will format a label on the y axis.  For
264           example:
265
266               $graph->y_label_formatter( sub { return '$' . $_[0] } );
267

EXAMPLES

269       For examples look at the project home page
270       http://leo.cuckoo.org/projects/SVG-TT-Graph/
271

EXPORT

273       None by default.
274

SEE ALSO

276       SVG::TT::Graph, SVG::TT::Graph::Bar, SVG::TT::Graph::BarHorizontal,
277       SVG::TT::Graph::BarLine, SVG::TT::Graph::Pie,
278       SVG::TT::Graph::TimeSeries, SVG::TT::Graph::XY, Compress::Zlib,
279       XML::Tidy
280
281
282
283perl v5.34.0                      2022-01-21           SVG::TT::Graph::Line(3)
Impressum