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