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