1SVG::TT::Graph::BarLineU(s3e)r Contributed Perl DocumentaStViGo:n:TT::Graph::BarLine(3)
2
3
4
6 SVG::TT::Graph::BarLine - Create presentation quality SVG bar-line
7 graphs easily
8
10 use SVG::TT::Graph::BarLine;
11
12 my @fields = qw(Jan Feb Mar);
13 my @data_sales_02 = qw(12 45 21);
14 my @data_sales_03 = (24, 55, 61);
15
16 my $graph = SVG::TT::Graph::BarLine->new({
17 'height' => '500',
18 'width' => '300',
19 'fields' => \@fields,
20 });
21
22 $graph->add_data({
23 'data' => \@data_sales_02,
24 'title' => 'Sales 2002',
25 });
26
27 $graph->add_data({
28 'data' => \@data_sales_03,
29 'title' => 'Sales 2003',
30 });
31
32 print "Content-type: image/svg+xml\n\n";
33 print $graph->burn();
34
36 This object aims to allow you to easily create high quality SVG bar
37 graphs. You can either use the default style sheet or supply your own.
38 Either way there are many options which can be configured to give you
39 control over how the graph is generated - with or without a key, data
40 elements at each point, title, subtitle etc.
41
43 new()
44 use SVG::TT::Graph::BarLine;
45
46 # Field names along the X axis
47 my @fields = qw(Jan Feb Mar);
48
49 my $graph = SVG::TT::Graph::BarLine->new({
50 # Required
51 'fields' => \@fields,
52
53 # Optional - defaults shown
54 'height' => '500',
55 'width' => '300',
56
57 'show_data_values' => 1,
58
59 'scale_divisions' => '',
60 'min_scale_value' => '0',
61 'bar_gap' => 1,
62
63 'show_x_labels' => 1,
64 'stagger_x_labels' => 0,
65 'rotate_x_labels' => 0,
66 'show_y_labels' => 1,
67 'scale_integers' => 0,
68 'show_secondary_y_labels' => 1,
69 'y_label_formatter' => sub { return @_ },
70 'x_label_formatter' => sub { return @_ },
71
72 'show_path_title' => 0,
73 'show_title_fields' => 0,
74
75 'show_x_title' => 0,
76 'x_title' => 'X Field names',
77
78 'show_y_title' => 0,
79 'show_secondary_y_title' => 0,
80 'y_title_text_direction' => 'bt',
81 'secondary_y_title_text_direction' => 'bt',
82 'y_title' => 'Y Scale',
83 'secondary_y_title' => 'Y Scale 2',
84
85 'show_graph_title' => 0,
86 'graph_title' => 'Graph Title',
87 'show_graph_subtitle' => 0,
88 'graph_subtitle' => 'Graph Sub Title',
89
90 'key' => 0,
91 'key_position' => 'right',
92
93 # Stylesheet defaults
94 'style_sheet' => '/includes/graph.css', # internal stylesheet
95 'random_colors' => 0,
96 });
97
98 The constructor takes a hash reference, fields (the names for each
99 field on the X axis) MUST be set, all other values are defaulted to
100 those shown above - with the exception of style_sheet which defaults to
101 using the internal style sheet.
102
103 add_data()
104 my @data_sales_02 = qw(12 45 21);
105
106 $graph->add_data({
107 'data' => \@data_sales_02,
108 'title' => 'Sales 2002',
109 });
110
111 This method allows you to add data to the graph object. It can be
112 called several times to add more data sets in, but the likelihood is
113 you should be using SVG::TT::Graph::Line as it won't look great!
114
115 clear_data()
116 my $graph->clear_data();
117
118 This method removes all data from the object so that you can reuse it
119 to create a new graph but with the same config options.
120
121 burn()
122 print $graph->burn();
123
124 This method processes the template with the data and config which has
125 been set and returns the resulting SVG.
126
127 This method will croak unless at least one data set has been added to
128 the graph object.
129
130 config methods
131 my $value = $graph->method();
132 my $confirmed_new_value = $graph->method($value);
133
134 The following is a list of the methods which are available to change
135 the config of the graph object after it has been created.
136
137 height()
138 Set the height of the graph box, this is the total height of the
139 SVG box created - not the graph it self which auto scales to fix
140 the space.
141
142 width()
143 Set the width of the graph box, this is the total width of the SVG
144 box created - not the graph it self which auto scales to fix the
145 space.
146
147 compress()
148 Whether or not to compress the content of the SVG file
149 (Compress::Zlib required).
150
151 tidy()
152 Whether or not to tidy the content of the SVG file (XML::Tidy
153 required).
154
155 style_sheet() =item style_sheet()
156 Set the path to an external stylesheet, set to '' if you want to
157 revert back to using the defaut internal version.
158
159 The default stylesheet handles up to 12 data sets. All data series
160 over the 12th will have no style and be in black. If you have over
161 12 data sets you can assign them all random colors (see the
162 random_color() method) or create your own stylesheet and add the
163 additional settings for the extra data sets.
164
165 To create an external stylesheet create a graph using the default
166 internal version and copy the stylesheet section to an external
167 file and edit from there.
168
169 random_colors()
170 Use random colors in the internal stylesheet
171
172 show_data_values()
173 Show the value of each element of data on the graph
174
175 bar_gap()
176 Whether to have a gap between the bars or not, default is '1', set
177 to '0' if you don't want gaps.
178
179 show_x_labels()
180 Whether to show labels on the X axis or not, defaults to 1, set to
181 '0' if you want to turn them off.
182
183 stagger_x_labels()
184 This puts the labels at alternative levels so if they are long
185 field names they will not overlap so easily. Default it '0', to
186 turn on set to '1'.
187
188 rotate_x_labels()
189 This turns the X axis labels by 90 degrees. Default it '0', to
190 turn on set to '1'.
191
192 show_y_labels()
193 Whether to show labels on the Y axis or not, defaults to 1, set to
194 '0' if you want to turn them off.
195
196 scale_integers()
197 Ensures only whole numbers are used as the scale divisions.
198 Default it '0', to turn on set to '1'. This has no effect if scale
199 divisions are less than 1.
200
201 show_secondary_y_labels()
202 Whether to show labels on the right hand side Y axis or not,
203 defaults to 1, set to '0' if you want to turn them off.
204
205 min_scale_value()
206 The point at which the Y axis starts, defaults to '0', if set to ''
207 it will default to the minimum data value.
208
209 scale_divisions()
210 This defines the gap between markers on the Y axis, default is a
211 10th of the max_value, e.g. you will have 10 markers on the Y axis.
212 NOTE: do not set this too low - you are limited to 999 markers,
213 after that the graph won't generate.
214
215 show_x_title()
216 Whether to show the title under the X axis labels, default is 0,
217 set to '1' to show.
218
219 x_title()
220 What the title under X axis should be, e.g. 'Months'.
221
222 show_y_title()
223 Whether to show the title on the left hand side Y axis, default is
224 0, set to '1' to show.
225
226 show_secondary_y_title()
227 Whether to show the title on the right hand side Y axis, default is
228 0, set to '1' to show.
229
230 y_title_text_direction()
231 Aligns writing mode for Y axis label. Defaults to 'bt' (Bottom to
232 Top). Change to 'tb' (Top to Bottom) to reverse.
233
234 secondary_y_title_text_direction()
235 Aligns writing mode for right hand Y axis label. Defaults to 'bt'
236 (Bottom to Top). Change to 'tb' (Top to Bottom) to reverse.
237
238 y_title()
239 What the title under Y axis should be, e.g. 'Sales in thousands'.
240
241 secondary_y_title()
242 What the title on the right hand side Y axis should be, e.g.
243 'Number of deals'.
244
245 show_graph_title()
246 Whether to show a title on the graph, defaults to 0, set to '1' to
247 show.
248
249 graph_title()
250 What the title on the graph should be.
251
252 show_graph_subtitle()
253 Whether to show a subtitle on the graph, defaults to 0, set to '1'
254 to show.
255
256 graph_subtitle()
257 What the subtitle on the graph should be.
258
259 key()
260 Whether to show a key, defaults to 0, set to '1' if you want to
261 show it.
262
263 key_position()
264 Where the key should be positioned, defaults to 'right', set to
265 'bottom' if you want to move it.
266
267 x_label_formatter ()
268 A callback subroutine which will format a label on the x axis. For
269 example:
270
271 $graph->x_label_formatter( sub { return '$' . $_[0] } );
272
273 y_label_formatter()
274 A callback subroutine which will format a label on the y axis. For
275 example:
276
277 $graph->y_label_formatter( sub { return '$' . $_[0] } );
278
279 show_path_title()
280 Whether to add the title attribute to the data path tags, which
281 will show "tooltips" when hovering over the bar area.
282
283 show_title_fields()
284 Whether to show field values as title elements in path tag,
285 defaults to 0, set to '1' to turn on. Suggest on single add_data
286 graphs, for overlapping graphs leave off to see the title value
287 used in the add_data call.
288
290 For examples look at the project home page
291 http://leo.cuckoo.org/projects/SVG-TT-Graph/
292
294 None by default.
295
297 SVG::TT::Graph, SVG::TT::Graph::Line, SVG::TT::Graph::Bar,
298 SVG::TT::Graph::BarHorizontal, SVG::TT::Graph::Pie,
299 SVG::TT::Graph::TimeSeries, SVG::TT::Graph::XY, Compress::Zlib,
300 XML::Tidy
301
302
303
304perl v5.28.1 2014-09-22 SVG::TT::Graph::BarLine(3)