1Spreadsheet::WriteExcelU:s:eCrhaCrotn:t:rSitbouctke(d3S)PperreladDsohceuemte:n:tWartiitoenExcel::Chart::Stock(3)
2
3
4

NAME

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

SYNOPSIS

9       To create a simple Excel file with a Stock 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 => 'stock' );
21
22           # Add a series for each Open-High-Low-Close.
23           $chart->add_series( categories => '=Sheet1!$A$2:$A$6', values => '=Sheet1!$B$2:$B$6' );
24           $chart->add_series( categories => '=Sheet1!$A$2:$A$6', values => '=Sheet1!$C$2:$C$6' );
25           $chart->add_series( categories => '=Sheet1!$A$2:$A$6', values => '=Sheet1!$D$2:$D$6' );
26           $chart->add_series( categories => '=Sheet1!$A$2:$A$6', values => '=Sheet1!$E$2:$E$6' );
27
28           # Add the worksheet data the chart refers to.
29           # ... See the full example below.
30
31           __END__
32

DESCRIPTION

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

Stock Chart Methods

52       There aren't currently any stock chart specific methods. See the TODO
53       section of Spreadsheet::WriteExcel::Chart.
54
55       The default Stock chart is an Open-High-Low-Close chart. A series must
56       be added for each of these data sources.
57
58       The default Stock chart is in black and white. User defined colours
59       will be added at a later stage.
60

EXAMPLE

62       Here is a complete example that demonstrates most of the available
63       features when creating a Stock chart.
64
65           #!/usr/bin/perl -w
66
67           use strict;
68           use Spreadsheet::WriteExcel;
69
70           my $workbook    = Spreadsheet::WriteExcel->new( 'chart_stock_ex.xls' );
71           my $worksheet   = $workbook->add_worksheet();
72           my $bold        = $workbook->add_format( bold => 1 );
73           my $date_format = $workbook->add_format( num_format => 'dd/mm/yyyy' );
74
75           # Add the worksheet data that the charts will refer to.
76           my $headings = [ 'Date', 'Open', 'High', 'Low', 'Close' ];
77           my @data = (
78               [ '2009-08-23', 110.75, 113.48, 109.05, 109.40 ],
79               [ '2009-08-24', 111.24, 111.60, 103.57, 104.87 ],
80               [ '2009-08-25', 104.96, 108.00, 103.88, 106.00 ],
81               [ '2009-08-26', 104.95, 107.95, 104.66, 107.91 ],
82               [ '2009-08-27', 108.10, 108.62, 105.69, 106.15 ],
83           );
84
85           $worksheet->write( 'A1', $headings, $bold );
86
87           my $row = 1;
88           for my $data ( @data ) {
89               $worksheet->write( $row, 0, $data->[0], $date_format );
90               $worksheet->write( $row, 1, $data->[1] );
91               $worksheet->write( $row, 2, $data->[2] );
92               $worksheet->write( $row, 3, $data->[3] );
93               $worksheet->write( $row, 4, $data->[4] );
94               $row++;
95           }
96
97           # Create a new chart object. In this case an embedded chart.
98           my $chart = $workbook->add_chart( type => 'stock', embedded => 1 );
99
100           # Add a series for each of the Open-High-Low-Close columns.
101           $chart->add_series(
102               categories => '=Sheet1!$A$2:$A$6',
103               values     => '=Sheet1!$B$2:$B$6',
104               name       => 'Open',
105           );
106
107           $chart->add_series(
108               categories => '=Sheet1!$A$2:$A$6',
109               values     => '=Sheet1!$C$2:$C$6',
110               name       => 'High',
111           );
112
113           $chart->add_series(
114               categories => '=Sheet1!$A$2:$A$6',
115               values     => '=Sheet1!$D$2:$D$6',
116               name       => 'Low',
117           );
118
119           $chart->add_series(
120               categories => '=Sheet1!$A$2:$A$6',
121               values     => '=Sheet1!$E$2:$E$6',
122               name       => 'Close',
123           );
124
125           # Add a chart title and some axis labels.
126           $chart->set_title( name => 'Open-High-Low-Close', );
127           $chart->set_x_axis( name => 'Date', );
128           $chart->set_y_axis( name => 'Share price', );
129
130           # Insert the chart into the worksheet (with an offset).
131           $worksheet->insert_chart( 'F2', $chart, 25, 10 );
132
133           __END__
134

AUTHOR

136       John McNamara jmcnamara@cpan.org
137
139       Copyright MM-MMX, John McNamara.
140
141       All Rights Reserved. This module is free software. It may be used,
142       redistributed and/or modified under the same terms as Perl itself.
143
144
145
146perl v5.34.0                      2021-S0p7r-e2a2dsheet::WriteExcel::Chart::Stock(3)
Impressum