| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
############################################################################### |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# Line - A class for writing Excel Line 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
|
91
|
|
|
91
|
|
6137
|
use strict; |
|
|
91
|
|
|
|
|
269
|
|
|
19
|
91
|
|
|
91
|
|
383
|
use warnings; |
|
|
91
|
|
|
|
|
168
|
|
|
|
91
|
|
|
|
|
1687
|
|
|
20
|
91
|
|
|
91
|
|
341
|
use Carp; |
|
|
91
|
|
|
|
|
160
|
|
|
|
91
|
|
|
|
|
1887
|
|
|
21
|
91
|
|
|
91
|
|
368
|
use Excel::Writer::XLSX::Chart; |
|
|
91
|
|
|
|
|
142
|
|
|
|
91
|
|
|
|
|
4743
|
|
|
22
|
91
|
|
|
91
|
|
435
|
|
|
|
91
|
|
|
|
|
161
|
|
|
|
91
|
|
|
|
|
41081
|
|
|
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
|
94
|
|
|
94
|
0
|
1565
|
|
|
36
|
94
|
|
|
|
|
358
|
$self->{_subtype} = $self->{_subtype} || 'standard'; |
|
37
|
|
|
|
|
|
|
$self->{_default_marker} = { type => 'none' }; |
|
38
|
94
|
|
100
|
|
|
438
|
$self->{_smooth_allowed} = 1; |
|
39
|
94
|
|
|
|
|
245
|
|
|
40
|
94
|
|
|
|
|
168
|
# Override and reset the default axis values. |
|
41
|
|
|
|
|
|
|
if ( $self->{_subtype} eq 'percent_stacked' ) { |
|
42
|
|
|
|
|
|
|
$self->{_y_axis}->{_defaults}->{num_format} = '0%'; |
|
43
|
94
|
100
|
|
|
|
307
|
} |
|
44
|
1
|
|
|
|
|
2
|
|
|
45
|
|
|
|
|
|
|
$self->set_y_axis(); |
|
46
|
|
|
|
|
|
|
|
|
47
|
94
|
|
|
|
|
364
|
# Set the available data label positions for this chart type. |
|
48
|
|
|
|
|
|
|
$self->{_label_position_default} = 'right'; |
|
49
|
|
|
|
|
|
|
$self->{_label_positions} = { |
|
50
|
94
|
|
|
|
|
165
|
center => 'ctr', |
|
51
|
|
|
|
|
|
|
right => 'r', |
|
52
|
94
|
|
|
|
|
488
|
left => 'l', |
|
53
|
|
|
|
|
|
|
above => 't', |
|
54
|
|
|
|
|
|
|
below => 'b', |
|
55
|
|
|
|
|
|
|
# For backward compatibility. |
|
56
|
|
|
|
|
|
|
top => 't', |
|
57
|
|
|
|
|
|
|
bottom => 'b', |
|
58
|
|
|
|
|
|
|
}; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
bless $self, $class; |
|
61
|
|
|
|
|
|
|
return $self; |
|
62
|
94
|
|
|
|
|
193
|
} |
|
63
|
94
|
|
|
|
|
293
|
|
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
############################################################################## |
|
66
|
|
|
|
|
|
|
# |
|
67
|
|
|
|
|
|
|
# _write_chart_type() |
|
68
|
|
|
|
|
|
|
# |
|
69
|
|
|
|
|
|
|
# Override the virtual superclass method with a chart specific method. |
|
70
|
|
|
|
|
|
|
# |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $self = shift; |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Write the c:lineChart element. |
|
75
|
184
|
|
|
184
|
|
339
|
$self->_write_line_chart( @_ ); |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
184
|
|
|
|
|
484
|
|
|
79
|
|
|
|
|
|
|
############################################################################## |
|
80
|
|
|
|
|
|
|
# |
|
81
|
|
|
|
|
|
|
# _write_line_chart() |
|
82
|
|
|
|
|
|
|
# |
|
83
|
|
|
|
|
|
|
# Write the <c:lineChart> element. |
|
84
|
|
|
|
|
|
|
# |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $self = shift; |
|
87
|
|
|
|
|
|
|
my %args = @_; |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my @series; |
|
90
|
184
|
|
|
184
|
|
274
|
if ( $args{primary_axes} ) { |
|
91
|
184
|
|
|
|
|
476
|
@series = $self->_get_primary_axes_series; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
184
|
|
|
|
|
268
|
else { |
|
94
|
184
|
100
|
|
|
|
523
|
@series = $self->_get_secondary_axes_series; |
|
95
|
92
|
|
|
|
|
655
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
return unless scalar @series; |
|
98
|
92
|
|
|
|
|
544
|
|
|
99
|
|
|
|
|
|
|
my $subtype = $self->{_subtype}; |
|
100
|
|
|
|
|
|
|
|
|
101
|
184
|
100
|
|
|
|
613
|
$subtype = 'percentStacked' if $subtype eq 'percent_stacked'; |
|
102
|
|
|
|
|
|
|
|
|
103
|
93
|
|
|
|
|
257
|
$self->xml_start_tag( 'c:lineChart' ); |
|
104
|
|
|
|
|
|
|
|
|
105
|
93
|
100
|
|
|
|
341
|
# Write the c:grouping element. |
|
106
|
|
|
|
|
|
|
$self->_write_grouping( $subtype ); |
|
107
|
93
|
|
|
|
|
374
|
|
|
108
|
|
|
|
|
|
|
# Write the series elements. |
|
109
|
|
|
|
|
|
|
$self->_write_series( $_ ) for @series; |
|
110
|
93
|
|
|
|
|
596
|
|
|
111
|
|
|
|
|
|
|
# Write the c:dropLines element. |
|
112
|
|
|
|
|
|
|
$self->_write_drop_lines(); |
|
113
|
93
|
|
|
|
|
520
|
|
|
114
|
|
|
|
|
|
|
# Write the c:hiLowLines element. |
|
115
|
|
|
|
|
|
|
$self->_write_hi_low_lines(); |
|
116
|
93
|
|
|
|
|
700
|
|
|
117
|
|
|
|
|
|
|
# Write the c:upDownBars element. |
|
118
|
|
|
|
|
|
|
$self->_write_up_down_bars(); |
|
119
|
93
|
|
|
|
|
531
|
|
|
120
|
|
|
|
|
|
|
# Write the c:marker element. |
|
121
|
|
|
|
|
|
|
$self->_write_marker_value(); |
|
122
|
93
|
|
|
|
|
522
|
|
|
123
|
|
|
|
|
|
|
# Write the c:axId elements |
|
124
|
|
|
|
|
|
|
$self->_write_axis_ids( %args ); |
|
125
|
93
|
|
|
|
|
370
|
|
|
126
|
|
|
|
|
|
|
$self->xml_end_tag( 'c:lineChart' ); |
|
127
|
|
|
|
|
|
|
} |
|
128
|
93
|
|
|
|
|
757
|
|
|
129
|
|
|
|
|
|
|
|
|
130
|
93
|
|
|
|
|
305
|
############################################################################## |
|
131
|
|
|
|
|
|
|
# |
|
132
|
|
|
|
|
|
|
# _write_d_pt_point() |
|
133
|
|
|
|
|
|
|
# |
|
134
|
|
|
|
|
|
|
# Write an individual <c:dPt> element. Override the parent method to add |
|
135
|
|
|
|
|
|
|
# markers. |
|
136
|
|
|
|
|
|
|
# |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
my $self = shift; |
|
139
|
|
|
|
|
|
|
my $index = shift; |
|
140
|
|
|
|
|
|
|
my $point = shift; |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
$self->xml_start_tag( 'c:dPt' ); |
|
143
|
1
|
|
|
1
|
|
2
|
|
|
144
|
1
|
|
|
|
|
2
|
# Write the c:idx element. |
|
145
|
1
|
|
|
|
|
1
|
$self->_write_idx( $index ); |
|
146
|
|
|
|
|
|
|
|
|
147
|
1
|
|
|
|
|
4
|
$self->xml_start_tag( 'c:marker' ); |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# Write the c:spPr element. |
|
150
|
1
|
|
|
|
|
4
|
$self->_write_sp_pr( $point ); |
|
151
|
|
|
|
|
|
|
|
|
152
|
1
|
|
|
|
|
2
|
$self->xml_end_tag( 'c:marker' ); |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
$self->xml_end_tag( 'c:dPt' ); |
|
155
|
1
|
|
|
|
|
5
|
} |
|
156
|
|
|
|
|
|
|
|
|
157
|
1
|
|
|
|
|
3
|
############################################################################## |
|
158
|
|
|
|
|
|
|
# |
|
159
|
1
|
|
|
|
|
2
|
# _write_marker_value() |
|
160
|
|
|
|
|
|
|
# |
|
161
|
|
|
|
|
|
|
# Write the <c:marker> element without a sub-element. |
|
162
|
|
|
|
|
|
|
# |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
my $self = shift; |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
my @attributes = ( 'val' => 1 ); |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
$self->xml_empty_tag( 'c:marker', @attributes ); |
|
169
|
|
|
|
|
|
|
} |
|
170
|
94
|
|
|
94
|
|
266
|
|
|
171
|
|
|
|
|
|
|
|
|
172
|
94
|
|
|
|
|
293
|
1; |
|
173
|
|
|
|
|
|
|
|
|
174
|
94
|
|
|
|
|
363
|
|
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 NAME |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Line - A class for writing Excel Line charts. |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
To create a simple Excel file with a Line chart using Excel::Writer::XLSX: |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
use strict; |
|
188
|
|
|
|
|
|
|
use warnings; |
|
189
|
|
|
|
|
|
|
use Excel::Writer::XLSX; |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
my $workbook = Excel::Writer::XLSX->new( 'chart.xlsx' ); |
|
192
|
|
|
|
|
|
|
my $worksheet = $workbook->add_worksheet(); |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
my $chart = $workbook->add_chart( type => 'line' ); |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
# Configure the chart. |
|
197
|
|
|
|
|
|
|
$chart->add_series( |
|
198
|
|
|
|
|
|
|
categories => '=Sheet1!$A$2:$A$7', |
|
199
|
|
|
|
|
|
|
values => '=Sheet1!$B$2:$B$7', |
|
200
|
|
|
|
|
|
|
); |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
# Add the worksheet data the chart refers to. |
|
203
|
|
|
|
|
|
|
my $data = [ |
|
204
|
|
|
|
|
|
|
[ 'Category', 2, 3, 4, 5, 6, 7 ], |
|
205
|
|
|
|
|
|
|
[ 'Value', 1, 4, 5, 2, 1, 5 ], |
|
206
|
|
|
|
|
|
|
]; |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
$worksheet->write( 'A1', $data ); |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
__END__ |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
This module implements Line charts for L<Excel::Writer::XLSX>. The chart object is created via the Workbook C<add_chart()> method: |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
my $chart = $workbook->add_chart( type => 'line' ); |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Once the object is created it can be configured via the following methods that are common to all chart classes: |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
$chart->add_series(); |
|
221
|
|
|
|
|
|
|
$chart->set_x_axis(); |
|
222
|
|
|
|
|
|
|
$chart->set_y_axis(); |
|
223
|
|
|
|
|
|
|
$chart->set_title(); |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
These methods are explained in detail in L<Excel::Writer::XLSX::Chart>. Class specific methods or settings, if any, are explained below. |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head1 Line Chart Subtypes |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
The C<Line> chart module also supports the following sub-types: |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
stacked |
|
233
|
|
|
|
|
|
|
percent_stacked |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
These can be specified at creation time via the C<add_chart()> Worksheet method: |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
my $chart = $workbook->add_chart( type => 'line', subtype => 'stacked' ); |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head1 EXAMPLE |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Here is a complete example that demonstrates most of the available features when creating a chart. |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
use strict; |
|
246
|
|
|
|
|
|
|
use warnings; |
|
247
|
|
|
|
|
|
|
use Excel::Writer::XLSX; |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
my $workbook = Excel::Writer::XLSX->new( 'chart_line.xlsx' ); |
|
250
|
|
|
|
|
|
|
my $worksheet = $workbook->add_worksheet(); |
|
251
|
|
|
|
|
|
|
my $bold = $workbook->add_format( bold => 1 ); |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
# Add the worksheet data that the charts will refer to. |
|
254
|
|
|
|
|
|
|
my $headings = [ 'Number', 'Batch 1', 'Batch 2' ]; |
|
255
|
|
|
|
|
|
|
my $data = [ |
|
256
|
|
|
|
|
|
|
[ 2, 3, 4, 5, 6, 7 ], |
|
257
|
|
|
|
|
|
|
[ 10, 40, 50, 20, 10, 50 ], |
|
258
|
|
|
|
|
|
|
[ 30, 60, 70, 50, 40, 30 ], |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
]; |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
$worksheet->write( 'A1', $headings, $bold ); |
|
263
|
|
|
|
|
|
|
$worksheet->write( 'A2', $data ); |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
# Create a new chart object. In this case an embedded chart. |
|
266
|
|
|
|
|
|
|
my $chart = $workbook->add_chart( type => 'line', embedded => 1 ); |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
# Configure the first series. |
|
269
|
|
|
|
|
|
|
$chart->add_series( |
|
270
|
|
|
|
|
|
|
name => '=Sheet1!$B$1', |
|
271
|
|
|
|
|
|
|
categories => '=Sheet1!$A$2:$A$7', |
|
272
|
|
|
|
|
|
|
values => '=Sheet1!$B$2:$B$7', |
|
273
|
|
|
|
|
|
|
); |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
# Configure second series. Note alternative use of array ref to define |
|
276
|
|
|
|
|
|
|
# ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ]. |
|
277
|
|
|
|
|
|
|
$chart->add_series( |
|
278
|
|
|
|
|
|
|
name => '=Sheet1!$C$1', |
|
279
|
|
|
|
|
|
|
categories => [ 'Sheet1', 1, 6, 0, 0 ], |
|
280
|
|
|
|
|
|
|
values => [ 'Sheet1', 1, 6, 2, 2 ], |
|
281
|
|
|
|
|
|
|
); |
|
282
|
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
# Add a chart title and some axis labels. |
|
284
|
|
|
|
|
|
|
$chart->set_title ( name => 'Results of sample analysis' ); |
|
285
|
|
|
|
|
|
|
$chart->set_x_axis( name => 'Test number' ); |
|
286
|
|
|
|
|
|
|
$chart->set_y_axis( name => 'Sample length (mm)' ); |
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
# Set an Excel chart style. Colors with white outline and shadow. |
|
289
|
|
|
|
|
|
|
$chart->set_style( 10 ); |
|
290
|
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
# Insert the chart into the worksheet (with an offset). |
|
292
|
|
|
|
|
|
|
$worksheet->insert_chart( 'D2', $chart, 25, 10 ); |
|
293
|
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
__END__ |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=begin html |
|
298
|
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
<p>This will produce a chart that looks like this:</p> |
|
300
|
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
<p><center><img src="http://jmcnamara.github.io/excel-writer-xlsx/images/examples/line1.jpg" width="483" height="291" alt="Chart example." /></center></p> |
|
302
|
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=end html |
|
304
|
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=head1 AUTHOR |
|
307
|
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
John McNamara jmcnamara@cpan.org |
|
309
|
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
311
|
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
Copyright MM-MMXXI, John McNamara. |
|
313
|
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself. |