1SVG::TT::Graph::Bar(3)User Contributed Perl DocumentationSVG::TT::Graph::Bar(3)
2
3
4
6 SVG::TT::Graph::Bar - Create presentation quality SVG bar graphs easily
7
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
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
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 'stagger_x_labels' => 0,
54 'rotate_x_labels' => 0,
55 'bar_gap' => 1,
56
57 'show_x_labels' => 1,
58 'show_y_labels' => 1,
59 'scale_integers' => 0,
60 'scale_divisions' => '',
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
74 'key' => 0,
75 'key_position' => 'right',
76
77 # Stylesheet defaults
78 'style_sheet' => '/includes/graph.css', # internal stylesheet
79 'random_colors' => 0,
80 });
81
82 The constructor takes a hash reference, fields (the names for each
83 field on the X axis) MUST be set, all other values are defaulted to
84 those shown above - with the exception of style_sheet which defaults to
85 using the internal style sheet.
86
87 add_data()
88 my @data_sales_02 = qw(12 45 21);
89
90 $graph->add_data({
91 'data' => \@data_sales_02,
92 'title' => 'Sales 2002',
93 });
94
95 This method allows you to add data to the graph object. It can be
96 called several times to add more data sets in, but the likelihood is
97 you should be using SVG::TT::Graph::Line as it won't look great!
98
99 clear_data()
100 my $graph->clear_data();
101
102 This method removes all data from the object so that you can reuse it
103 to create a new graph but with the same config options.
104
105 burn()
106 print $graph->burn();
107
108 This method processes the template with the data and config which has
109 been set and returns the resulting SVG.
110
111 This method will croak unless at least one data set has been added to
112 the graph object.
113
114 config methods
115 my $value = $graph->method();
116 my $confirmed_new_value = $graph->method($value);
117
118 The following is a list of the methods which are available to change
119 the config of the graph object after it has been created.
120
121 height()
122 Set the height of the graph box, this is the total height of the
123 SVG box created - not the graph it self which auto scales to fix
124 the space.
125
126 width()
127 Set the width of the graph box, this is the total width of the SVG
128 box created - not the graph it self which auto scales to fix the
129 space.
130
131 compress()
132 Whether or not to compress the content of the SVG file
133 (Compress::Zlib required).
134
135 tidy()
136 Whether or not to tidy the content of the SVG file (XML::Tidy
137 required).
138
139 style_sheet()
140 Set the path to an external stylesheet, set to '' if you want to
141 revert back to using the defaut internal version.
142
143 The default stylesheet handles up to 12 data sets. All data series
144 over the 12th will have no style and be in black. If you have over
145 12 data sets you can assign them all random colors (see the
146 random_color() method) or create your own stylesheet and add the
147 additional settings for the extra data sets.
148
149 To create an external stylesheet create a graph using the default
150 internal version and copy the stylesheet section to an external
151 file and edit from there.
152
153 random_colors()
154 Use random colors in the internal stylesheet
155
156 show_data_values()
157 Show the value of each element of data on the graph
158
159 bar_gap()
160 Whether to have a gap between the bars or not, default is '1', set
161 to '0' if you don't want gaps.
162
163 min_scale_value()
164 The point at which the Y axis starts, defaults to '0', if set to ''
165 it will default to the minimum data value.
166
167 show_x_labels()
168 Whether to show labels on the X axis or not, defaults to 1, set to
169 '0' if you want to turn them off.
170
171 stagger_x_labels()
172 This puts the labels at alternative levels so if they are long
173 field names they will not overlap so easily. Default it '0', to
174 turn on set to '1'.
175
176 rotate_x_labels()
177 This turns the X axis labels by 90 degrees. 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 Y axis, default is a
191 10th of the max_value, e.g. you will have 10 markers on the Y 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, defaults to 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, defaults to 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
236 For examples look at the project home page
237 http://leo.cuckoo.org/projects/SVG-TT-Graph/
238
240 None by default.
241
243 Stephen Morgan for creating the TT template and SVG.
244
246 Leo Lapworth (LLAP@cuckoo.org)
247
249 SVG::TT::Graph, SVG::TT::Graph::Line, SVG::TT::Graph::BarHorizontal,
250 SVG::TT::Graph::BarLine, SVG::TT::Graph::Pie,
251 SVG::TT::Graph::TimeSeries, Compress::Zlib, XML::Tidy
252
253
254
255perl v5.12.0 2010-04-17 SVG::TT::Graph::Bar(3)