1Excel::Writer::XLSX::ChUasretr::CSocnattrtiebru(t3e)d PeErxlceDlo:c:uWmreintteart:i:oXnLSX::Chart::Scatter(3)
2
3
4

NAME

6       Scatter - A class for writing Excel Scatter charts.
7

SYNOPSIS

9       To create a simple Excel file with a Scatter 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 => 'scatter' );
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

DESCRIPTION

40       This module implements Scatter charts for Excel::Writer::XLSX. The
41       chart object is created via the Workbook "add_chart()" method:
42
43           my $chart = $workbook->add_chart( type => 'scatter' );
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

Scatter Chart Subtypes

57       The "Scatter" chart module also supports the following sub-types:
58
59           markers_only (the default)
60           straight_with_markers
61           straight
62           smooth_with_markers
63           smooth
64
65       These can be specified at creation time via the "add_chart()" Worksheet
66       method:
67
68           my $chart = $workbook->add_chart(
69               type    => 'scatter',
70               subtype => 'straight_with_markers'
71           );
72

EXAMPLE

74       Here is a complete example that demonstrates most of the available
75       features when creating a chart.
76
77           #!/usr/bin/perl
78
79           use strict;
80           use warnings;
81           use Excel::Writer::XLSX;
82
83           my $workbook  = Excel::Writer::XLSX->new( 'chart_scatter.xlsx' );
84           my $worksheet = $workbook->add_worksheet();
85           my $bold      = $workbook->add_format( bold => 1 );
86
87           # Add the worksheet data that the charts will refer to.
88           my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
89           my $data = [
90               [ 2, 3, 4, 5, 6, 7 ],
91               [ 10, 40, 50, 20, 10, 50 ],
92               [ 30, 60, 70, 50, 40, 30 ],
93
94           ];
95
96           $worksheet->write( 'A1', $headings, $bold );
97           $worksheet->write( 'A2', $data );
98
99           # Create a new chart object. In this case an embedded chart.
100           my $chart = $workbook->add_chart( type => 'scatter', embedded => 1 );
101
102           # Configure the first series.
103           $chart->add_series(
104               name       => '=Sheet1!$B$1',
105               categories => '=Sheet1!$A$2:$A$7',
106               values     => '=Sheet1!$B$2:$B$7',
107           );
108
109           # Configure second series. Note alternative use of array ref to define
110           # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
111           $chart->add_series(
112               name       => '=Sheet1!$C$1',
113               categories => [ 'Sheet1', 1, 6, 0, 0 ],
114               values     => [ 'Sheet1', 1, 6, 2, 2 ],
115           );
116
117           # Add a chart title and some axis labels.
118           $chart->set_title ( name => 'Results of sample analysis' );
119           $chart->set_x_axis( name => 'Test number' );
120           $chart->set_y_axis( name => 'Sample length (mm)' );
121
122           # Set an Excel chart style. Colors with white outline and shadow.
123           $chart->set_style( 10 );
124
125           # Insert the chart into the worksheet (with an offset).
126           $worksheet->insert_chart( 'D2', $chart, 25, 10 );
127
128           __END__
129

AUTHOR

131       John McNamara jmcnamara@cpan.org
132
134       Copyright MM-MMXX, John McNamara.
135
136       All Rights Reserved. This module is free software. It may be used,
137       redistributed and/or modified under the same terms as Perl itself.
138
139
140
141perl v5.32.1                      2021-01E-x2c7el::Writer::XLSX::Chart::Scatter(3)
Impressum