1SVG::TT::Graph::Pie(3)User Contributed Perl DocumentationSVG::TT::Graph::Pie(3)
2
3
4
6 SVG::TT::Graph::Pie - Create presentation quality SVG pie graphs easily
7
9 use SVG::TT::Graph::Pie;
10
11 my @fields = qw(Jan Feb Mar);
12 my @data_sales_02 = qw(12 45 21);
13
14 my $graph = SVG::TT::Graph::Pie->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 pie
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,
33 display percent on pie chart, title, subtitle etc.
34
36 new()
37 use SVG::TT::Graph::Pie;
38
39 # Field names along the X axis
40 my @fields = qw(Jan Feb Mar);
41
42 my $graph = SVG::TT::Graph::Pie->new({
43 # Required
44 'fields' => \@fields,
45
46 # Optional - defaults shown
47 'height' => '500',
48 'width' => '300',
49
50 'show_graph_title' => 0,
51 'graph_title' => 'Graph Title',
52 'show_graph_subtitle' => 0,
53 'graph_subtitle' => 'Graph Sub Title',
54
55 'show_shadow' => 1,
56 'shadow_size' => 1,
57 'shadow_offset' => 15,
58
59 'key_placement' => 'R',
60
61 # data by pie chart wedges:
62 'show_data_labels' => 0,
63 'show_actual_values' => 0,
64 'show_percent' => 1,
65 'rollover_values' => 0,
66 'show_path_title' => 0,
67 'show_title_fields' => 0,
68
69 # data on key:
70 'show_key_data_labels' => 1,
71 'show_key_actual_values' => 1,
72 'show_key_percent' => 0,
73
74 'expanded' => 0,
75 'expand_greatest' => 0,
76
77 # Stylesheet defaults
78 'style_sheet' => '/includes/graph.css', # internal stylesheet
79 'style_sheet_field_names' => 0,
80 'random_colors' => 0,
81
82 });
83
84 The constructor takes a hash reference, fields (the name for each slice
85 on the pie) MUST be set, all other values are defaulted to those shown
86 above - with the exception of style_sheet which defaults to using the
87 internal style sheet.
88
89 add_data()
90 my @data_sales_02 = qw(12 45 21);
91
92 $graph->add_data({
93 'data' => \@data_sales_02,
94 'title' => 'Sales 2002',
95 });
96
97 This method allows you to add data to the graph object, only the first
98 data set added will be used!
99
100 clear_data()
101 my $graph->clear_data();
102
103 This method removes all data from the object so that you can reuse it
104 to create a new graph but with the same config options.
105
106 burn()
107 print $graph->burn();
108
109 This method processes the template with the data and config which has
110 been set and returns the resulting SVG.
111
112 This method will croak unless at least one data set has been added to
113 the graph object.
114
115 config methods
116 my $value = $graph->method();
117 my $confirmed_new_value = $graph->method($value);
118
119 The following is a list of the methods which are available to change
120 the config of the graph object after it has been created.
121
122 height()
123 Set the height of the graph box, this is the total height of the
124 SVG box created - not the graph it self which auto scales to fix
125 the space.
126
127 width()
128 Set the width of the graph box, this is the total width of the SVG
129 box created - not the graph it self which auto scales to fix the
130 space.
131
132 compress()
133 Whether or not to compress the content of the SVG file
134 (Compress::Zlib required).
135
136 tidy()
137 Whether or not to tidy the content of the SVG file (XML::Tidy
138 required).
139
140 style_sheet()
141 Set the path to an external stylesheet, set to '' if you want to
142 revert back to using the defaut internal version.
143
144 The default stylesheet handles up to 12 data sets. All data series
145 over the 12th will have no style and be in black. If you have over
146 12 data sets you can assign them all random colors (see the
147 random_color() method) or create your own stylesheet and add the
148 additional settings for the extra data sets.
149
150 To create an external stylesheet create a graph using the default
151 internal version and copy the stylesheet section to an external
152 file and edit from there.
153
154 random_colors()
155 Use random colors in the internal stylesheet
156
157 style_sheet_field_names()
158 If you use the style_sheet_field_names() option then you can use
159 the field names within your stylesheet. This allows consistent use
160 of styles. The names should be:
161
162 <field>_dataPoint
163 <field>_key
164 show_graph_title()
165 Whether to show a title on the graph, default is '0'.
166
167 graph_title()
168 What the title on the graph should be.
169
170 show_graph_subtitle()
171 Whether to show a subtitle on the graph, default is '0'.
172
173 graph_subtitle()
174 What the subtitle on the graph should be.
175
176 show_shadow()
177 Turn the shadow on and off, default to '1', set to '0' if you don't
178 want it. It is automatically turned off if you extract one section
179 of the pie.
180
181 shadow_size()
182 Size of the shadow if shown, measured as percentage of pie chart
183 radius, default of 1 being the same size as the pie.
184
185 shadow_offset()
186 Offset (in pixels) of shadow to bottom-right in relation to the
187 center of the pie chart.
188
189 key()
190 Whether to show a key, defaults to 0, set to '1' if you want to
191 show it.
192
193 key_placement()
194 Defaults to 'R' - right, can be 'R', 'L', 'T' or 'B'.
195
196 show_data_labels()
197 Show label on pie chart, defaults to '0', can be set to '1'.
198
199 show_actual_values()
200 Show values on pie chart, defaults to '0', can be set to '1'.
201
202 show_percent()
203 Show percent (rounded) on the pie chart, defaults to '1', can be
204 set to '0'.
205
206 rollover_values()
207 Shows data field and value when the mouse is over a piechart wedge.
208
209 show_path_title()
210 Whether to add the title attribute to the data path tags, which
211 will show "tooltips" when hovering over the bar area.
212
213 show_title_fields()
214 Whether to show field values as title elements in path tag,
215 defaults to 0, set to '1' to turn on. Suggest on single add_data
216 graphs, for overlapping graphs leave off to see the title value
217 used in the add_data call.
218
219 show_key_data_labels()
220 Show label on the key, defaults to '1', can be set to '0'.
221
222 show_key_actual_values()
223 Show value on the key, defaults to '1', can be set to '0'.
224
225 show_key_percent()
226 Show percent (rounded) on the key, defaults to '0', can be set to
227 '1'.
228
229 expanded()
230 All slices of pie are exploded out, defaults to '0'. Do not set to
231 '1' if you are going to use expanded_greatest().
232
233 expand_greatest()
234 The largest slice of pie is exploded out from the pie, defaults to
235 '0'. Useful if you are only showing the percentages (which are
236 rounded) but still want to visually show which slice was largest.
237
238 Do not set to '1' if you are going to use expanded().
239
241 For examples look at the project home page
242 http://leo.cuckoo.org/projects/SVG-TT-Graph/
243
245 None by default.
246
248 SVG::TT::Graph, SVG::TT::Graph::Line, SVG::TT::Graph::Bar,
249 SVG::TT::Graph::BarHorizontal, SVG::TT::Graph::BarLine,
250 SVG::TT::Graph::TimeSeries, SVG::TT::Graph::XY, Compress::Zlib,
251 XML::Tidy
252
253
254
255perl v5.28.1 2014-09-22 SVG::TT::Graph::Pie(3)