1SVG::TT::Graph::BarHoriUzsoenrtaClo(n3t)ributed Perl DocSuVmGe:n:tTaTt:i:oGnraph::BarHorizontal(3)
2
3
4

NAME

6       SVG::TT::Graph::BarHorizontal - Create presentation quality SVG
7       horizontal bar graphs easily
8

SYNOPSIS

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

DESCRIPTION

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

METHODS

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

EXAMPLES

258       For examples look at the project home page
259       http://leo.cuckoo.org/projects/SVG-TT-Graph/
260

EXPORT

262       None by default.
263

SEE ALSO

265       SVG::TT::Graph, SVG::TT::Graph::Line, SVG::TT::Graph::Bar,
266       SVG::TT::Graph::BarLine, SVG::TT::Graph::Pie,
267       SVG::TT::Graph::TimeSeries, SVG::TT::Graph::XY, Compress::Zlib,
268       XML::Tidy
269
270
271
272perl v5.28.1                      2014-09-22  SVG::TT::Graph::BarHorizontal(3)
Impressum