1SVG::TT::Graph::Bar(3)User Contributed Perl DocumentationSVG::TT::Graph::Bar(3)
2
3
4

NAME

6       SVG::TT::Graph::Bar - Create presentation quality SVG bar graphs easily
7

SYNOPSIS

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

DESCRIPTION

29       This object aims to allow you to easily create high quality SVG bar
30       graphs. You can either use the default style sheet or supply your own.
31       Either way there are many options which can be configured to give you
32       control over how the graph is generated - with or without a key, data
33       elements at each point, title, subtitle etc.
34

METHODS

36   new()
37         use SVG::TT::Graph::Bar;
38
39         # Field names along the X axis
40         my @fields = qw(Jan Feb Mar);
41
42         my $graph = SVG::TT::Graph::Bar->new({
43           # Required
44           'fields'                 => \@fields,
45
46           # Optional - defaults shown
47           'height'                 => '500',
48           'width'                  => '300',
49
50           'show_data_values'       => 1,
51
52           'min_scale_value'        => '0',
53           'max_scale_value'        => undef,
54           'stagger_x_labels'       => 0,
55           'rotate_x_labels'        => 0,
56           'bar_gap'                => 1,
57
58           'show_x_labels'          => 1,
59           'show_y_labels'          => 1,
60           'scale_integers'         => 0,
61           'scale_divisions'        => '',
62           'y_label_formatter'      => sub { return @_ },
63           'x_label_formatter'      => sub { return @_ },
64
65           'show_path_title'        => 0,
66           'show_title_fields'      => 0,
67
68           'show_x_title'           => 0,
69           'x_title'                => 'X Field names',
70
71           'show_y_title'           => 0,
72           'y_title_text_direction' => 'bt',
73           'y_title'                => 'Y Scale',
74
75           'show_graph_title'       => 0,
76           'graph_title'            => 'Graph Title',
77           'show_graph_subtitle'    => 0,
78           'graph_subtitle'         => 'Graph Sub Title',
79
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, fields (the names for each
89       field on the X axis) MUST be set, all other values are defaulted to
90       those shown above - with the exception of style_sheet which defaults to
91       using the internal style sheet.
92
93   add_data()
94         my @data_sales_02 = qw(12 45 21);
95
96         $graph->add_data({
97           'data' => \@data_sales_02,
98           'title' => 'Sales 2002',
99         });
100
101       This method allows you to add data to the graph object.  It can be
102       called several times to add more data sets in, but the likelihood is
103       you should be using SVG::TT::Graph::Line as it won't look great!
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 width 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       bar_gap()
166           Whether to have a gap between the bars or not, default is '1', set
167           to '0' if you don't want gaps.
168
169       min_scale_value()
170           The point at which the Y axis starts, defaults to '0', if set to ''
171           it will default to the minimum data value.
172
173       max_scale_value()
174           The maximum value for the Y axis.  If set to '', it will default to
175           the maximum 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       stagger_x_labels()
182           This puts the labels at alternative levels so if they are long
183           field names they will not overlap so easily.  Default it '0', to
184           turn on set to '1'.
185
186       rotate_x_labels()
187           This turns the X axis labels by 90 degrees.  Default it '0', to
188           turn on set to '1'.
189
190       show_y_labels()
191           Whether to show labels on the Y axis or not, defaults to 1, set to
192           '0' if you want to turn them off.
193
194       scale_integers()
195           Ensures only whole numbers are used as the scale divisions.
196           Default it '0', to turn on set to '1'. This has no effect if scale
197           divisions are less than 1.
198
199       scale_divisions()
200           This defines the gap between markers on the Y axis, default is a
201           10th of the max_value, e.g. you will have 10 markers on the Y axis.
202           NOTE: do not set this too low - you are limited to 999 markers,
203           after that the graph won't generate.
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, defaults to 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, defaults to 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
245       x_label_formatter ()
246           A callback subroutine which will format a label on the x axis.  For
247           example:
248
249               $graph->x_label_formatter( sub { return '$' . $_[0] } );
250
251       y_label_formatter()
252           A callback subroutine which will format a label on the y axis.  For
253           example:
254
255               $graph->y_label_formatter( sub { return '$' . $_[0] } );
256
257       show_path_title()
258           Whether to add the title attribute to the data path tags, which
259           will show "tooltips" when hovering over the bar area.
260
261       show_title_fields()
262           Whether to show field values as title elements in path tag,
263           defaults to 0, set to '1' to turn on. Suggest on single add_data
264           graphs, for overlapping graphs leave off to see the title value
265           used in the add_data call.
266

EXAMPLES

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

EXPORT

272       None by default.
273

SEE ALSO

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