line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
############################################################################### |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Radar - A class for writing Excel Radar charts. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Used in conjunction with Excel::Writer::XLSX::Chart. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# See formatting note in Excel::Writer::XLSX::Chart. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Copyright 2000-2021, John McNamara, jmcnamara@cpan.org |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# Documentation after __END__ |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# perltidy with the following options: -mbl=2 -pt=0 -nola |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use 5.008002; |
18
|
6
|
|
|
6
|
|
145
|
use strict; |
|
6
|
|
|
|
|
22
|
|
19
|
6
|
|
|
6
|
|
27
|
use warnings; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
127
|
|
20
|
6
|
|
|
6
|
|
25
|
use Carp; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
160
|
|
21
|
6
|
|
|
6
|
|
26
|
use Excel::Writer::XLSX::Chart; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
383
|
|
22
|
6
|
|
|
6
|
|
32
|
|
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
2442
|
|
23
|
|
|
|
|
|
|
our @ISA = qw(Excel::Writer::XLSX::Chart); |
24
|
|
|
|
|
|
|
our $VERSION = '1.09'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
############################################################################### |
28
|
|
|
|
|
|
|
# |
29
|
|
|
|
|
|
|
# new() |
30
|
|
|
|
|
|
|
# |
31
|
|
|
|
|
|
|
# |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $class = shift; |
34
|
|
|
|
|
|
|
my $self = Excel::Writer::XLSX::Chart->new( @_ ); |
35
|
6
|
|
|
6
|
0
|
14
|
|
36
|
6
|
|
|
|
|
25
|
$self->{_subtype} = $self->{_subtype} || 'marker'; |
37
|
|
|
|
|
|
|
|
38
|
6
|
|
100
|
|
|
26
|
if ( $self->{_subtype} eq 'marker' ) { |
39
|
|
|
|
|
|
|
$self->{_default_marker} = { type => 'none' }; |
40
|
6
|
100
|
|
|
|
19
|
} |
41
|
4
|
|
|
|
|
18
|
|
42
|
|
|
|
|
|
|
# Override and reset the default axis values. |
43
|
|
|
|
|
|
|
$self->{_x_axis}->{_defaults}->{major_gridlines} = { visible => 1 }; |
44
|
|
|
|
|
|
|
$self->set_x_axis(); |
45
|
6
|
|
|
|
|
15
|
|
46
|
6
|
|
|
|
|
21
|
# Hardcode major_tick_mark for now until there is an accessor. |
47
|
|
|
|
|
|
|
$self->{_y_axis}->{_major_tick_mark} = 'cross'; |
48
|
|
|
|
|
|
|
|
49
|
6
|
|
|
|
|
12
|
# Set the available data label positions for this chart type. |
50
|
|
|
|
|
|
|
$self->{_label_position_default} = 'center'; |
51
|
|
|
|
|
|
|
$self->{_label_positions} = { center => 'ctr' }; |
52
|
6
|
|
|
|
|
12
|
|
53
|
6
|
|
|
|
|
16
|
bless $self, $class; |
54
|
|
|
|
|
|
|
|
55
|
6
|
|
|
|
|
15
|
return $self; |
56
|
|
|
|
|
|
|
} |
57
|
6
|
|
|
|
|
22
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
############################################################################## |
60
|
|
|
|
|
|
|
# |
61
|
|
|
|
|
|
|
# _write_chart_type() |
62
|
|
|
|
|
|
|
# |
63
|
|
|
|
|
|
|
# Override the virtual superclass method with a chart specific method. |
64
|
|
|
|
|
|
|
# |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $self = shift; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Write the c:radarChart element. |
69
|
12
|
|
|
12
|
|
31
|
$self->_write_radar_chart( @_ ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
12
|
|
|
|
|
33
|
|
73
|
|
|
|
|
|
|
############################################################################## |
74
|
|
|
|
|
|
|
# |
75
|
|
|
|
|
|
|
# _write_radar_chart() |
76
|
|
|
|
|
|
|
# |
77
|
|
|
|
|
|
|
# Write the <c:radarChart> element. |
78
|
|
|
|
|
|
|
# |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $self = shift; |
81
|
|
|
|
|
|
|
my %args = @_; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my @series; |
84
|
12
|
|
|
12
|
|
20
|
if ( $args{primary_axes} ) { |
85
|
12
|
|
|
|
|
32
|
@series = $self->_get_primary_axes_series; |
86
|
|
|
|
|
|
|
} |
87
|
12
|
|
|
|
|
20
|
else { |
88
|
12
|
100
|
|
|
|
36
|
@series = $self->_get_secondary_axes_series; |
89
|
6
|
|
|
|
|
47
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
return unless scalar @series; |
92
|
6
|
|
|
|
|
37
|
|
93
|
|
|
|
|
|
|
$self->xml_start_tag( 'c:radarChart' ); |
94
|
|
|
|
|
|
|
|
95
|
12
|
100
|
|
|
|
39
|
# Write the c:radarStyle element. |
96
|
|
|
|
|
|
|
$self->_write_radar_style(); |
97
|
6
|
|
|
|
|
31
|
|
98
|
|
|
|
|
|
|
# Write the series elements. |
99
|
|
|
|
|
|
|
$self->_write_series( $_ ) for @series; |
100
|
6
|
|
|
|
|
25
|
|
101
|
|
|
|
|
|
|
# Write the c:axId elements |
102
|
|
|
|
|
|
|
$self->_write_axis_ids( %args ); |
103
|
6
|
|
|
|
|
50
|
|
104
|
|
|
|
|
|
|
$self->xml_end_tag( 'c:radarChart' ); |
105
|
|
|
|
|
|
|
} |
106
|
6
|
|
|
|
|
100
|
|
107
|
|
|
|
|
|
|
|
108
|
6
|
|
|
|
|
23
|
############################################################################## |
109
|
|
|
|
|
|
|
# |
110
|
|
|
|
|
|
|
# _write_radar_style() |
111
|
|
|
|
|
|
|
# |
112
|
|
|
|
|
|
|
# Write the <c:radarStyle> element. |
113
|
|
|
|
|
|
|
# |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
my $self = shift; |
116
|
|
|
|
|
|
|
my $val = 'marker'; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
if ( $self->{_subtype} eq 'filled' ) { |
119
|
|
|
|
|
|
|
$val = 'filled'; |
120
|
6
|
|
|
6
|
|
13
|
} |
121
|
6
|
|
|
|
|
14
|
|
122
|
|
|
|
|
|
|
my @attributes = ( 'val' => $val ); |
123
|
6
|
100
|
|
|
|
25
|
|
124
|
1
|
|
|
|
|
1
|
$self->xml_empty_tag( 'c:radarStyle', @attributes ); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
6
|
|
|
|
|
18
|
|
128
|
|
|
|
|
|
|
1; |
129
|
6
|
|
|
|
|
39
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 NAME |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Radar - A class for writing Excel Radar charts. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 SYNOPSIS |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
To create a simple Excel file with a Radar chart using Excel::Writer::XLSX: |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
#!/usr/bin/perl |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
use strict; |
144
|
|
|
|
|
|
|
use warnings; |
145
|
|
|
|
|
|
|
use Excel::Writer::XLSX; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
my $workbook = Excel::Writer::XLSX->new( 'chart.xlsx' ); |
148
|
|
|
|
|
|
|
my $worksheet = $workbook->add_worksheet(); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
my $chart = $workbook->add_chart( type => 'radar' ); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# Configure the chart. |
153
|
|
|
|
|
|
|
$chart->add_series( |
154
|
|
|
|
|
|
|
categories => '=Sheet1!$A$2:$A$7', |
155
|
|
|
|
|
|
|
values => '=Sheet1!$B$2:$B$7', |
156
|
|
|
|
|
|
|
); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# Add the worksheet data the chart refers to. |
159
|
|
|
|
|
|
|
my $data = [ |
160
|
|
|
|
|
|
|
[ 'Category', 2, 3, 4, 5, 6, 7 ], |
161
|
|
|
|
|
|
|
[ 'Value', 1, 4, 5, 2, 1, 5 ], |
162
|
|
|
|
|
|
|
]; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
$worksheet->write( 'A1', $data ); |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
__END__ |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 DESCRIPTION |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This module implements Radar charts for L<Excel::Writer::XLSX>. The chart object is created via the Workbook C<add_chart()> method: |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
my $chart = $workbook->add_chart( type => 'radar' ); |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Once the object is created it can be configured via the following methods that are common to all chart classes: |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
$chart->add_series(); |
177
|
|
|
|
|
|
|
$chart->set_x_axis(); |
178
|
|
|
|
|
|
|
$chart->set_y_axis(); |
179
|
|
|
|
|
|
|
$chart->set_title(); |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
These methods are explained in detail in L<Excel::Writer::XLSX::Chart>. Class specific methods or settings, if any, are explained below. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 Radar Chart Methods |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
The C<Radar> chart module also supports the following sub-types: |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
with_markers |
188
|
|
|
|
|
|
|
filled |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
These can be specified at creation time via the C<add_chart()> Worksheet method: |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
my $chart = $workbook->add_chart( type => 'radar', subtype => 'filled' ); |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 EXAMPLE |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Here is a complete example that demonstrates most of the available features when creating a chart. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
#!/usr/bin/perl |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
use strict; |
201
|
|
|
|
|
|
|
use warnings; |
202
|
|
|
|
|
|
|
use Excel::Writer::XLSX; |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
my $workbook = Excel::Writer::XLSX->new( 'chart_radar.xlsx' ); |
205
|
|
|
|
|
|
|
my $worksheet = $workbook->add_worksheet(); |
206
|
|
|
|
|
|
|
my $bold = $workbook->add_format( bold => 1 ); |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
# Add the worksheet data that the charts will refer to. |
209
|
|
|
|
|
|
|
my $headings = [ 'Number', 'Batch 1', 'Batch 2' ]; |
210
|
|
|
|
|
|
|
my $data = [ |
211
|
|
|
|
|
|
|
[ 2, 3, 4, 5, 6, 7 ], |
212
|
|
|
|
|
|
|
[ 30, 60, 70, 50, 40, 30 ], |
213
|
|
|
|
|
|
|
[ 25, 40, 50, 30, 50, 40 ], |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
]; |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
$worksheet->write( 'A1', $headings, $bold ); |
218
|
|
|
|
|
|
|
$worksheet->write( 'A2', $data ); |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
# Create a new chart object. In this case an embedded chart. |
221
|
|
|
|
|
|
|
my $chart = $workbook->add_chart( type => 'radar', embedded => 1 ); |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
# Configure the first series. |
224
|
|
|
|
|
|
|
$chart->add_series( |
225
|
|
|
|
|
|
|
name => '=Sheet1!$B$1', |
226
|
|
|
|
|
|
|
categories => '=Sheet1!$A$2:$A$7', |
227
|
|
|
|
|
|
|
values => '=Sheet1!$B$2:$B$7', |
228
|
|
|
|
|
|
|
); |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
# Configure second series. Note alternative use of array ref to define |
231
|
|
|
|
|
|
|
# ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ]. |
232
|
|
|
|
|
|
|
$chart->add_series( |
233
|
|
|
|
|
|
|
name => '=Sheet1!$C$1', |
234
|
|
|
|
|
|
|
categories => [ 'Sheet1', 1, 6, 0, 0 ], |
235
|
|
|
|
|
|
|
values => [ 'Sheet1', 1, 6, 2, 2 ], |
236
|
|
|
|
|
|
|
); |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
# Add a chart title and some axis labels. |
239
|
|
|
|
|
|
|
$chart->set_title ( name => 'Results of sample analysis' ); |
240
|
|
|
|
|
|
|
$chart->set_x_axis( name => 'Test number' ); |
241
|
|
|
|
|
|
|
$chart->set_y_axis( name => 'Sample length (mm)' ); |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
# Set an Excel chart style. Colors with white outline and shadow. |
244
|
|
|
|
|
|
|
$chart->set_style( 10 ); |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
# Insert the chart into the worksheet (with an offset). |
247
|
|
|
|
|
|
|
$worksheet->insert_chart( 'D2', $chart, 25, 10 ); |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
__END__ |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=begin html |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
<p>This will produce a chart that looks like this:</p> |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
<p><center><img src="http://jmcnamara.github.io/excel-writer-xlsx/images/examples/radar1.jpg" width="483" height="291" alt="Chart example." /></center></p> |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=end html |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head1 AUTHOR |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
John McNamara jmcnamara@cpan.org |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=head1 COPYRIGHT |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
Copyright MM-MMXXI, John McNamara. |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself. |