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
67 # data on key:
68 'show_key_data_labels' => 1,
69 'show_key_actual_values' => 1,
70 'show_key_percent' => 0,
71
72 'expanded' => 0,
73 'expand_greatest' => 0,
74
75 # Stylesheet defaults
76 'style_sheet' => '/includes/graph.css', # internal stylesheet
77 'style_sheet_field_names' => 0,
78 'random_colors' => 0,
79
80 });
81
82 The constructor takes a hash reference, fields (the name for each slice
83 on the pie) MUST be set, all other values are defaulted to those shown
84 above - with the exception of style_sheet which defaults to using the
85 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, only the first
96 data set added will be used!
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 style_sheet_field_names()
156 If you use the style_sheet_field_names() option then you can use
157 the field names within your stylesheet. This allows consistent use
158 of styles. The names should be:
159
160 <field>_dataPoint
161 <field>_key
162 show_graph_title()
163 Whether to show a title on the graph, default is '0'.
164
165 graph_title()
166 What the title on the graph should be.
167
168 show_graph_subtitle()
169 Whether to show a subtitle on the graph, default is '0'.
170
171 graph_subtitle()
172 What the subtitle on the graph should be.
173
174 show_shadow()
175 Turn the shadow on and off, default to '1', set to '0' if you don't
176 want it. It is automatically turned off if you extract one section
177 of the pie.
178
179 shadow_size()
180 Size of the shadow if shown, measured as percentage of pie chart
181 radius, default of 1 being the same size as the pie.
182
183 shadow_offset()
184 Offset (in pixels) of shadow to bottom-right in relation to the
185 center of the pie chart.
186
187 key()
188 Whether to show a key, defaults to 0, set to '1' if you want to
189 show it.
190
191 key_placement()
192 Defaults to 'R' - right, can be 'R', 'L', 'T' or 'B'.
193
194 show_data_labels()
195 Show label on pie chart, defaults to '0', can be set to '1'.
196
197 show_actual_values()
198 Show values on pie chart, defaults to '0', can be set to '1'.
199
200 show_percent()
201 Show percent (rounded) on the pie chart, defaults to '1', can be
202 set to '0'.
203
204 rollover_values()
205 Shows data field and value when the mouse is over a piechart wedge.
206
207 show_key_data_labels()
208 Show label on the key, defaults to '1', can be set to '0'.
209
210 show_key_actual_values()
211 Show value on the key, defaults to '1', can be set to '0'.
212
213 show_key_percent()
214 Show percent (rounded) on the key, defaults to '0', can be set to
215 '1'.
216
217 expanded()
218 All slices of pie are exploded out, defaults to '0'. Do not set to
219 '1' if you are going to use expanded_greatest().
220
221 expand_greatest()
222 The largest slice of pie is exploded out from the pie, defaults to
223 '0'. Useful if you are only showing the percentages (which are
224 rounded) but still want to visually show which slice was largest.
225
226 Do not set to '1' if you are going to use expanded().
227
229 For examples look at the project home page
230 http://leo.cuckoo.org/projects/SVG-TT-Graph/
231
233 None by default.
234
236 Stephen Morgan for creating the TT template and SVG.
237
239 Leo Lapworth (LLAP@cuckoo.org)
240
242 SVG::TT::Graph, SVG::TT::Graph::Line, SVG::TT::Graph::Bar,
243 SVG::TT::Graph::BarHorizontal, SVG::TT::Graph::BarLine,
244 SVG::TT::Graph::TimeSeries, Compress::Zlib, XML::Tidy
245
246
247
248perl v5.12.0 2010-04-17 SVG::TT::Graph::Pie(3)