~ubuntu-branches/ubuntu/intrepid/horae/intrepid

« back to all changes in this revision

Viewing changes to 0CPAN/Spreadsheet-WriteExcel-2.15/charts/demo3.pl

  • Committer: Bazaar Package Importer
  • Author(s): Carlo Segre
  • Date: 2008-02-23 23:13:02 UTC
  • mfrom: (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080223231302-mnyyxs3icvrus4ke
Tags: 066-3
Apply patch to athena_parts/misc.pl for compatibility with 
perl-tk 804.28.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl -w
2
 
 
3
 
###############################################################################
4
 
#
5
 
# Simple example of how to add an externally created chart to a Spreadsheet::
6
 
# WriteExcel file.
7
 
#
8
 
#
9
 
# This example adds an "Open-high-low-close" stock chart extracted from the
10
 
# file Chart3.xls as follows:
11
 
#
12
 
#   perl chartex.pl -c=demo3 Chart3.xls
13
 
#
14
 
# reverse('�'), September 2004, John McNamara, jmcnamara@cpan.org
15
 
#
16
 
 
17
 
use strict;
18
 
use Spreadsheet::WriteExcel;
19
 
 
20
 
my $workbook  = Spreadsheet::WriteExcel->new("demo3.xls");
21
 
my $worksheet = $workbook->add_worksheet();
22
 
 
23
 
 
24
 
# Add the chart extracted using the chartex utility
25
 
my $chart     = $workbook->add_chart_ext('demo301.bin', 'Chart1');
26
 
 
27
 
 
28
 
# Link the chart to the worksheet data using a dummy formula.
29
 
$worksheet->store_formula('=Sheet1!A1');
30
 
 
31
 
 
32
 
# Add some extra formats to cover formats used in the charts.
33
 
$workbook->add_format(color => 1);
34
 
$workbook->add_format(color => 2);
35
 
$workbook->add_format(color => 3, bold => 1);
36
 
$workbook->add_format(color => 4);
37
 
 
38
 
 
39
 
# Add all other formats.
40
 
my $bold        = $workbook->add_format(bold => 1);
41
 
my $date_format = $workbook->add_format(num_format => 'dd/mm/yyyy');
42
 
 
43
 
 
44
 
# Adjust column widths and add some headers
45
 
$worksheet->set_column('A:A', 12);
46
 
 
47
 
$worksheet->write('A1', 'Date',  $bold);
48
 
$worksheet->write('B1', 'Open',  $bold);
49
 
$worksheet->write('C1', 'High',  $bold);
50
 
$worksheet->write('D1', 'Low', $bold);
51
 
$worksheet->write('E1', 'Close', $bold);
52
 
 
53
 
 
54
 
# Add data to range that the chart refers to.
55
 
my @dates = (
56
 
 
57
 
   "2004-08-19T",
58
 
   "2004-08-20T",
59
 
   "2004-08-23T",
60
 
   "2004-08-24T",
61
 
   "2004-08-25T",
62
 
   "2004-08-26T",
63
 
   "2004-08-27T",
64
 
   "2004-08-30T",
65
 
   "2004-08-31T",
66
 
   "2004-09-01T",
67
 
   "2004-09-02T",
68
 
   "2004-09-03T",
69
 
   "2004-09-07T",
70
 
   "2004-09-08T",
71
 
   "2004-09-09T",
72
 
   "2004-09-10T",
73
 
   "2004-09-13T",
74
 
   "2004-09-14T",
75
 
   "2004-09-15T",
76
 
   "2004-09-16T",
77
 
   "2004-09-17T",
78
 
   "2004-09-20T",
79
 
   "2004-09-21T",
80
 
);
81
 
 
82
 
# Open-High-Low-Close prices
83
 
my @prices = (
84
 
 
85
 
    [100.00, 104.06,  95.96, 100.34],
86
 
    [101.01, 109.08, 100.50, 108.31],
87
 
    [110.75, 113.48, 109.05, 109.40],
88
 
    [111.24, 111.60, 103.57, 104.87],
89
 
    [104.96, 108.00, 103.88, 106.00],
90
 
    [104.95, 107.95, 104.66, 107.91],
91
 
    [108.10, 108.62, 105.69, 106.15],
92
 
    [105.28, 105.49, 102.01, 102.01],
93
 
    [102.30, 103.71, 102.16, 102.37],
94
 
    [102.70, 102.97,  99.67, 100.25],
95
 
    [ 99.19, 102.37,  98.94, 101.51],
96
 
    [100.95, 101.74,  99.32, 100.01],
97
 
    [101.01, 102.00,  99.61, 101.58],
98
 
    [100.74, 103.03, 100.50, 102.30],
99
 
    [102.53, 102.71, 101.00, 102.31],
100
 
    [101.60, 106.56, 101.30, 105.33],
101
 
    [106.63, 108.41, 106.46, 107.50],
102
 
    [107.45, 112.00, 106.79, 111.49],
103
 
    [110.56, 114.23, 110.20, 112.00],
104
 
    [112.34, 115.80, 111.65, 113.97],
105
 
    [114.42, 117.49, 113.55, 117.49],
106
 
    [116.95, 121.60, 116.77, 119.36],
107
 
    [119.81, 120.42, 117.51, 117.84],
108
 
);
109
 
 
110
 
 
111
 
 
112
 
my $row = 1;
113
 
$worksheet->write_date_time($row++, 0, $_, $date_format) for @dates;
114
 
$worksheet->write_col('B2', \@prices);