1Excel::Writer::XLSX::ChUasretr::CLoinnter(i3b)uted PerlEDxocceulm:e:nWtraittieorn::XLSX::Chart::Line(3)
2
3
4
6 Line - A class for writing Excel Line charts.
7
9 To create a simple Excel file with a Line chart using
10 Excel::Writer::XLSX:
11
12 #!/usr/bin/perl
13
14 use strict;
15 use warnings;
16 use Excel::Writer::XLSX;
17
18 my $workbook = Excel::Writer::XLSX->new( 'chart.xlsx' );
19 my $worksheet = $workbook->add_worksheet();
20
21 my $chart = $workbook->add_chart( type => 'line' );
22
23 # Configure the chart.
24 $chart->add_series(
25 categories => '=Sheet1!$A$2:$A$7',
26 values => '=Sheet1!$B$2:$B$7',
27 );
28
29 # Add the worksheet data the chart refers to.
30 my $data = [
31 [ 'Category', 2, 3, 4, 5, 6, 7 ],
32 [ 'Value', 1, 4, 5, 2, 1, 5 ],
33 ];
34
35 $worksheet->write( 'A1', $data );
36
37 __END__
38
40 This module implements Line charts for Excel::Writer::XLSX. The chart
41 object is created via the Workbook "add_chart()" method:
42
43 my $chart = $workbook->add_chart( type => 'line' );
44
45 Once the object is created it can be configured via the following
46 methods that are common to all chart classes:
47
48 $chart->add_series();
49 $chart->set_x_axis();
50 $chart->set_y_axis();
51 $chart->set_title();
52
53 These methods are explained in detail in Excel::Writer::XLSX::Chart.
54 Class specific methods or settings, if any, are explained below.
55
57 There aren't currently any line chart specific methods. See the TODO
58 section of Excel::Writer::XLSX::Chart.
59
61 Here is a complete example that demonstrates most of the available
62 features when creating a chart.
63
64 #!/usr/bin/perl
65
66 use strict;
67 use warnings;
68 use Excel::Writer::XLSX;
69
70 my $workbook = Excel::Writer::XLSX->new( 'chart_line.xlsx' );
71 my $worksheet = $workbook->add_worksheet();
72 my $bold = $workbook->add_format( bold => 1 );
73
74 # Add the worksheet data that the charts will refer to.
75 my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
76 my $data = [
77 [ 2, 3, 4, 5, 6, 7 ],
78 [ 10, 40, 50, 20, 10, 50 ],
79 [ 30, 60, 70, 50, 40, 30 ],
80
81 ];
82
83 $worksheet->write( 'A1', $headings, $bold );
84 $worksheet->write( 'A2', $data );
85
86 # Create a new chart object. In this case an embedded chart.
87 my $chart = $workbook->add_chart( type => 'line', embedded => 1 );
88
89 # Configure the first series.
90 $chart->add_series(
91 name => '=Sheet1!$B$1',
92 categories => '=Sheet1!$A$2:$A$7',
93 values => '=Sheet1!$B$2:$B$7',
94 );
95
96 # Configure second series. Note alternative use of array ref to define
97 # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
98 $chart->add_series(
99 name => '=Sheet1!$C$1',
100 categories => [ 'Sheet1', 1, 6, 0, 0 ],
101 values => [ 'Sheet1', 1, 6, 2, 2 ],
102 );
103
104 # Add a chart title and some axis labels.
105 $chart->set_title ( name => 'Results of sample analysis' );
106 $chart->set_x_axis( name => 'Test number' );
107 $chart->set_y_axis( name => 'Sample length (mm)' );
108
109 # Set an Excel chart style. Colors with white outline and shadow.
110 $chart->set_style( 10 );
111
112 # Insert the chart into the worksheet (with an offset).
113 $worksheet->insert_chart( 'D2', $chart, 25, 10 );
114
115 __END__
116
118 John McNamara jmcnamara@cpan.org
119
121 Copyright MM-MMXVIII, John McNamara.
122
123 All Rights Reserved. This module is free software. It may be used,
124 redistributed and/or modified under the same terms as Perl itself.
125
126
127
128perl v5.28.0 2018-04-14Excel::Writer::XLSX::Chart::Line(3)