CPAN::Forum
Spreadsheet-WriteExcel - Re: Help with Multiple charts using chartex
| Posted on Thu Apr 14 21:13:54 2005 by marfolarfo in response to 340 (See the whole thread of 8) |
| Re: Help with Multiple charts using chartex |
|
Let me try this again so you can read it.
Create a demo402.xls file that contains this starting at A1
worksheet2
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
It also contains a chart sheet named chart1. It charts this data as a bar graph using A1 as the cha
+rt label , A2-A11 as the x-axis, and B2-B11 as the data.
Do the same for demo401.xls. It shall contain the same thing except for A1 which should say workshe
+et1.
Run chartex.pl demo401.xls
Rename chart01.bin to demo401.bin
Run chartex.pl demp402.xls
Rename chart01.bin to demo402.bin
Run the following code. The resulting spreadsheet will have two charts with identical labels and da
+ta; the data and label from the first chart generated.
#!/usr/bin/perl -w use strict;
use Spreadsheet::WriteExcel;
my $workbook = Spreadsheet::WriteExcel->new("demo4.xls");
my $worksheet1 = $workbook->add_worksheet();
my $worksheet2 = $workbook->add_worksheet();
my $chart1 = $workbook->add_chart_ext('demo401.bin', 'Chart1');
my $chart2 = $workbook->add_chart_ext('demo402.bin', 'Chart2');
# Link the chart to the worksheet data using a dummy formula. $worksheet1->store_formula('=Sheet1!A
+2');
$worksheet1->store_formula('=Sheet2!A2');
# Add some extra formats to cover formats used in the charts.
$workbook->add_format(color => 1);
$workbook->add_format(color => 2);
$workbook->add_format(color => 3);
$workbook->add_format(color => 4);
# Add all other formats (if any).
# Add data to range that the chart refers to.
my @nums = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
my @squares = map {$_**2} @nums;
my @cubes = map {$_**3} @nums;
$worksheet1->write(0, 0, "worksheet1" );
$worksheet1->write_col('A2', \@nums );
$worksheet1->write_col('B2', \@squares);
$worksheet2->write(0, 0, "worksheet2" );
$worksheet2->write_col('A2', \@nums );
$worksheet2->write_col('B2', \@cubes );
|
| Direct Responses: 343 | Write a response |
(19)
]