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

EXAMPLES

262       For examples look at the project home page
263       http://leo.cuckoo.org/projects/SVG-TT-Graph/
264

EXPORT

266       None by default.
267

SEE ALSO

269       SVG::TT::Graph, SVG::TT::Graph::Line, SVG::TT::Graph::Bar,
270       SVG::TT::Graph::BarLine, SVG::TT::Graph::Pie,
271       SVG::TT::Graph::TimeSeries, SVG::TT::Graph::XY, Compress::Zlib,
272       XML::Tidy
273
274
275
276perl v5.32.0                      2020-07-28  SVG::TT::Graph::BarHorizontal(3)
Impressum