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 Set to "inline:<style>...</style>" with your CSS in between the
145 tags. You can thus override the default style without requireing
146 an external URL.
147
148 The default stylesheet handles up to 12 data sets. All data series
149 over the 12th will have no style and be in black. If you have over
150 12 data sets you can assign them all random colors (see the
151 random_color() method) or create your own stylesheet and add the
152 additional settings for the extra data sets.
153
154 To create an external stylesheet create a graph using the default
155 internal version and copy the stylesheet section to an external
156 file and edit from there.
157
158 random_colors()
159 Use random colors in the internal stylesheet
160
161 style_sheet_field_names()
162 If you use the style_sheet_field_names() option then you can use
163 the field names within your stylesheet. This allows consistent use
164 of styles. The names should be:
165
166 <field>_dataPoint
167 <field>_key
168 show_graph_title()
169 Whether to show a title on the graph, default is '0'.
170
171 graph_title()
172 What the title on the graph should be.
173
174 show_graph_subtitle()
175 Whether to show a subtitle on the graph, default is '0'.
176
177 graph_subtitle()
178 What the subtitle on the graph should be.
179
180 show_shadow()
181 Turn the shadow on and off, default to '1', set to '0' if you don't
182 want it. It is automatically turned off if you extract one section
183 of the pie.
184
185 shadow_size()
186 Size of the shadow if shown, measured as percentage of pie chart
187 radius, default of 1 being the same size as the pie.
188
189 shadow_offset()
190 Offset (in pixels) of shadow to bottom-right in relation to the
191 center of the pie chart.
192
193 key()
194 Whether to show a key, defaults to 0, set to '1' if you want to
195 show it.
196
197 key_placement()
198 Defaults to 'R' - right, can be 'R', 'L', 'T' or 'B'.
199
200 show_data_labels()
201 Show label on pie chart, defaults to '0', can be set to '1'.
202
203 show_actual_values()
204 Show values on pie chart, defaults to '0', can be set to '1'.
205
206 show_percent()
207 Show percent (rounded) on the pie chart, defaults to '1', can be
208 set to '0'.
209
210 rollover_values()
211 Shows data field and value when the mouse is over a piechart wedge.
212
213 show_path_title()
214 Whether to add the title attribute to the data path tags, which
215 will show "tooltips" when hovering over the bar area.
216
217 show_title_fields()
218 Whether to show field values as title elements in path tag,
219 defaults to 0, set to '1' to turn on. Suggest on single add_data
220 graphs, for overlapping graphs leave off to see the title value
221 used in the add_data call.
222
223 show_key_data_labels()
224 Show label on the key, defaults to '1', can be set to '0'.
225
226 show_key_actual_values()
227 Show value on the key, defaults to '1', can be set to '0'.
228
229 show_key_percent()
230 Show percent (rounded) on the key, defaults to '0', can be set to
231 '1'.
232
233 expanded()
234 All slices of pie are exploded out, defaults to '0'. Do not set to
235 '1' if you are going to use expanded_greatest().
236
237 expand_greatest()
238 The largest slice of pie is exploded out from the pie, defaults to
239 '0'. Useful if you are only showing the percentages (which are
240 rounded) but still want to visually show which slice was largest.
241
242 Do not set to '1' if you are going to use expanded().
243
245 For examples look at the project home page
246 http://leo.cuckoo.org/projects/SVG-TT-Graph/
247
249 None by default.
250
252 SVG::TT::Graph, SVG::TT::Graph::Line, SVG::TT::Graph::Bar,
253 SVG::TT::Graph::BarHorizontal, SVG::TT::Graph::BarLine,
254 SVG::TT::Graph::TimeSeries, SVG::TT::Graph::XY, Compress::Zlib,
255 XML::Tidy
256
257
258
259perl v5.36.0 2023-01-20 SVG::TT::Graph::Pie(3)