1Excel::Writer::XLSX::ChUasretr::CSotnotcrki(b3u)ted PerlExDcoeclu:m:eWnrtiatteiro:n:XLSX::Chart::Stock(3)
2
3
4
6 Stock - A class for writing Excel Stock charts.
7
9 To create a simple Excel file with a Stock chart using
10 Excel::Writer::XLSX:
11
12 #!/usr/bin/perl -w
13
14 use strict;
15 use Excel::Writer::XLSX;
16
17 my $workbook = Excel::Writer::XLSX->new( 'chart.xlsx' );
18 my $worksheet = $workbook->add_worksheet();
19
20 my $chart = $workbook->add_chart( type => 'stock' );
21
22 # Add a series for each High-Low-Close.
23 $chart->add_series(
24 categories => '=Sheet1!$A$2:$A$6',
25 values => '=Sheet1!$B$2:$B$6'
26 );
27
28 $chart->add_series(
29 categories => '=Sheet1!$A$2:$A$6',
30 values => '=Sheet1!$C$2:$C$6'
31 );
32
33 $chart->add_series(
34 categories => '=Sheet1!$A$2:$A$6',
35 values => '=Sheet1!$D$2:$D$6'
36 );
37
38 # Add the worksheet data the chart refers to.
39 # ... See the full example below.
40
41 __END__
42
44 This module implements Stock charts for Excel::Writer::XLSX. The chart
45 object is created via the Workbook add_chart() method:
46
47 my $chart = $workbook->add_chart( type => 'stock' );
48
49 Once the object is created it can be configured via the following
50 methods that are common to all chart classes:
51
52 $chart->add_series();
53 $chart->set_x_axis();
54 $chart->set_y_axis();
55 $chart->set_title();
56
57 These methods are explained in detail in Excel::Writer::XLSX::Chart.
58 Class specific methods or settings, if any, are explained below.
59
61 There aren't currently any stock chart specific methods. See the TODO
62 section of Excel::Writer::XLSX::Chart.
63
64 The default Stock chart is a High-Low-Close chart. A series must be
65 added for each of these data sources.
66
68 Here is a complete example that demonstrates most of the available
69 features when creating a Stock chart.
70
71 #!/usr/bin/perl
72
73 use strict;
74 use warnings;
75 use Excel::Writer::XLSX;
76 use Excel::Writer::XLSX;
77
78 my $workbook = Excel::Writer::XLSX->new( 'chart_stock.xlsx' );
79 my $worksheet = $workbook->add_worksheet();
80 my $bold = $workbook->add_format( bold => 1 );
81 my $date_format = $workbook->add_format( num_format => 'dd/mm/yyyy' );
82 my $chart = $workbook->add_chart( type => 'stock', embedded => 1 );
83
84
85 # Add the worksheet data that the charts will refer to.
86 my $headings = [ 'Date', 'High', 'Low', 'Close' ];
87 my $data = [
88
89 [ '2007-01-01T', '2007-01-02T', '2007-01-03T', '2007-01-04T', '2007-01-05T' ],
90 [ 27.2, 25.03, 19.05, 20.34, 18.5 ],
91 [ 23.49, 19.55, 15.12, 17.84, 16.34 ],
92 [ 25.45, 23.05, 17.32, 20.45, 17.34 ],
93
94 ];
95
96 $worksheet->write( 'A1', $headings, $bold );
97
98 for my $row ( 0 .. 4 ) {
99 $worksheet->write_date_time( $row+1, 0, $data->[0]->[$row], $date_format );
100 $worksheet->write( $row+1, 1, $data->[1]->[$row] );
101 $worksheet->write( $row+1, 2, $data->[2]->[$row] );
102 $worksheet->write( $row+1, 3, $data->[3]->[$row] );
103
104 }
105
106 $worksheet->set_column( 'A:D', 11 );
107
108 # Add a series for each of the High-Low-Close columns.
109 $chart->add_series(
110 categories => '=Sheet1!$A$2:$A$6',
111 values => '=Sheet1!$B$2:$B$6',
112 );
113
114 $chart->add_series(
115 categories => '=Sheet1!$A$2:$A$6',
116 values => '=Sheet1!$C$2:$C$6',
117 );
118
119 $chart->add_series(
120 categories => '=Sheet1!$A$2:$A$6',
121 values => '=Sheet1!$D$2:$D$6',
122 );
123
124 # Add a chart title and some axis labels.
125 $chart->set_title ( name => 'High-Low-Close', );
126 $chart->set_x_axis( name => 'Date', );
127 $chart->set_y_axis( name => 'Share price', );
128
129
130 $worksheet->insert_chart( 'E9', $chart );
131
132 __END__
133
135 John McNamara jmcnamara@cpan.org
136
138 Copyright MM-MMXXI, John McNamara.
139
140 All Rights Reserved. This module is free software. It may be used,
141 redistributed and/or modified under the same terms as Perl itself.
142
143
144
145perl v5.36.0 2023-01-2E0xcel::Writer::XLSX::Chart::Stock(3)