1SVG::TT::Graph::BarLineU(s3e)r Contributed Perl DocumentaStViGo:n:TT::Graph::BarLine(3)
2
3
4

NAME

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

SYNOPSIS

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

EXAMPLES

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

EXPORT

298       None by default.
299

SEE ALSO

301       SVG::TT::Graph, SVG::TT::Graph::Line, SVG::TT::Graph::Bar,
302       SVG::TT::Graph::BarHorizontal, SVG::TT::Graph::Pie,
303       SVG::TT::Graph::TimeSeries, SVG::TT::Graph::XY, Compress::Zlib,
304       XML::Tidy
305
306
307
308perl v5.30.0                      2019-07-26        SVG::TT::Graph::BarLine(3)
Impressum