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

EXAMPLES

246       For examples look at the project home page
247       http://leo.cuckoo.org/projects/SVG-TT-Graph/
248

EXPORT

250       None by default.
251

ACKNOWLEDGEMENTS

253       Stephen Morgan for creating the TT template and SVG.
254

AUTHOR

256       Leo Lapworth (LLAP@cuckoo.org)
257

SEE ALSO

259       SVG::TT::Graph, SVG::TT::Graph::Bar, SVG::TT::Graph::BarHorizontal,
260       SVG::TT::Graph::BarLine, SVG::TT::Graph::Pie,
261       SVG::TT::Graph::TimeSeries, Compress::Zlib, XML::Tidy
262
263
264
265perl v5.12.0                      2010-04-17           SVG::TT::Graph::Line(3)
Impressum