1Spreadsheet::WriteExcelU:s:eCrhaCrotn:t:rLiibnuet(e3d)PSeprrleaDdoschuemeetn:t:aWtriiotneExcel::Chart::Line(3)
2
3
4

NAME

6       Line - A writer class for Excel Line charts.
7

SYNOPSIS

9       To create a simple Excel file with a Line chart using
10       Spreadsheet::WriteExcel:
11
12           #!/usr/bin/perl -w
13
14           use strict;
15           use Spreadsheet::WriteExcel;
16
17           my $workbook  = Spreadsheet::WriteExcel->new( 'chart.xls' );
18           my $worksheet = $workbook->add_worksheet();
19
20           my $chart     = $workbook->add_chart( type => 'line' );
21
22           # Configure the chart.
23           $chart->add_series(
24               categories => '=Sheet1!$A$2:$A$7',
25               values     => '=Sheet1!$B$2:$B$7',
26           );
27
28           # Add the worksheet data the chart refers to.
29           my $data = [
30               [ 'Category', 2, 3, 4, 5, 6, 7 ],
31               [ 'Value',    1, 4, 5, 2, 1, 5 ],
32           ];
33
34           $worksheet->write( 'A1', $data );
35
36           __END__
37

DESCRIPTION

39       This module implements Line charts for Spreadsheet::WriteExcel. The
40       chart object is created via the Workbook "add_chart()" method:
41
42           my $chart = $workbook->add_chart( type => 'line' );
43
44       Once the object is created it can be configured via the following
45       methods that are common to all chart classes:
46
47           $chart->add_series();
48           $chart->set_x_axis();
49           $chart->set_y_axis();
50           $chart->set_title();
51
52       These methods are explained in detail in
53       Spreadsheet::WriteExcel::Chart. Class specific methods or settings, if
54       any, are explained below.
55

Line Chart Methods

57       There aren't currently any line chart specific methods. See the TODO
58       section of Spreadsheet::WriteExcel::Chart.
59

EXAMPLE

61       Here is a complete example that demonstrates most of the available
62       features when creating a chart.
63
64           #!/usr/bin/perl -w
65
66           use strict;
67           use Spreadsheet::WriteExcel;
68
69           my $workbook  = Spreadsheet::WriteExcel->new( 'chart_line.xls' );
70           my $worksheet = $workbook->add_worksheet();
71           my $bold      = $workbook->add_format( bold => 1 );
72
73           # Add the worksheet data that the charts will refer to.
74           my $headings = [ 'Number', 'Sample 1', 'Sample 2' ];
75           my $data = [
76               [ 2, 3, 4, 5, 6, 7 ],
77               [ 1, 4, 5, 2, 1, 5 ],
78               [ 3, 6, 7, 5, 4, 3 ],
79           ];
80
81           $worksheet->write( 'A1', $headings, $bold );
82           $worksheet->write( 'A2', $data );
83
84           # Create a new chart object. In this case an embedded chart.
85           my $chart = $workbook->add_chart( type => 'line', embedded => 1 );
86
87           # Configure the first series. (Sample 1)
88           $chart->add_series(
89               name       => 'Sample 1',
90               categories => '=Sheet1!$A$2:$A$7',
91               values     => '=Sheet1!$B$2:$B$7',
92           );
93
94           # Configure the second series. (Sample 2)
95           $chart->add_series(
96               name       => 'Sample 2',
97               categories => '=Sheet1!$A$2:$A$7',
98               values     => '=Sheet1!$C$2:$C$7',
99           );
100
101           # Add a chart title and some axis labels.
102           $chart->set_title ( name => 'Results of sample analysis' );
103           $chart->set_x_axis( name => 'Test number' );
104           $chart->set_y_axis( name => 'Sample length (cm)' );
105
106           # Insert the chart into the worksheet (with an offset).
107           $worksheet->insert_chart( 'D2', $chart, 25, 10 );
108
109           __END__
110

AUTHOR

112       John McNamara jmcnamara@cpan.org
113
115       Copyright MM-MMX, John McNamara.
116
117       All Rights Reserved. This module is free software. It may be used,
118       redistributed and/or modified under the same terms as Perl itself.
119
120
121
122perl v5.36.0                      2022-0S7p-r2e2adsheet::WriteExcel::Chart::Line(3)
Impressum