Thread

Posted on Wed Apr 13 16:28:52 2005 by marfolarfo
Help with Multiple charts using chartex
I am using the chartex command to generate three different binary chart templates for use with the spreadsheet Perl modules. I am using the following code segment inside a loop to generate three different chart sheets based on the data in three different work sheets.
$workbook->add_chart_ext($majPhase . 'chart01.bin', $majPhase . 'chart' ); # Link the chart to the worksheet data using a dummy formula. $worksheet->store_formula('=' . $majPhase . '!I2');
This is working nicely except for one rather nasty problem. All three charts are the same. They all are using the teplate and data from the first generated chart sheet. I have read all the documentation I can find and tried various thing, all to know avail. Can anyone tell me what I am doing wrong.
Direct Responses: 332 | Write a response
Posted on Thu Apr 14 03:02:32 2005 by jmcnamara in response to 330
Re: Help with Multiple charts using chartex

Hi,

I couldn't reproduce your bug.

I created a workbook with two worksheets with data in cells A1:B10 and two charts which referred to the worksheet data.

I then extracted the charts and ran the program below

#!/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!A1'); $worksheet1->store_formula('=Sheet2!A1'); # 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_col('A1', \@nums ); $worksheet1->write_col('B1', \@squares); $worksheet2->write_col('A1', \@nums ); $worksheet2->write_col('B1', \@cubes );

The output from this was fine. Which isn't to say that there isn't a bug. Only that I couldn't reproduce it. :-)

So the best thing to do is post a complete (but minimal) example that demonstrates the problem.


John.
--
Direct Responses: 340 | Write a response
Posted on Thu Apr 14 21:02:06 2005 by marfolarfo in response to 332
Re: Help with Multiple charts using chartex
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 chart 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 worksheet1. 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 data; 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!A2'); $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: 341 | Write a response
Posted on Thu Apr 14 21:13:54 2005 by marfolarfo in response to 340
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
Posted on Fri Apr 15 01:22:00 2005 by jmcnamara in response to 341
Re: Help with Multiple charts using chartex
> Create a demo402.xls file that contains this starting at A1
> ...
> Do the same for demo401.xls.

This is the cause of the problem.

If you wish to use two chart templates then you have to create them in the same workbook.

A future release will allow greater flexibility but for now try to keep the templating process as simple as possible.

John.
--
Direct Responses: 349 | 5565 | Write a response
Posted on Fri Apr 15 21:04:40 2005 by marfolarfo in response to 343
Re: Help with Multiple charts using chartex
John, Thanks once again. This cleared up my problem. Neat tool. I have a feeling I will be using this more as they seem to, more and more, want data generated on Unix machines put into excel spreadsheets.
Write a response
Posted on Fri Jun 29 07:56:22 2007 by narsi in response to 343
Re: Help with Multiple charts using chartex
Hi, I would like create multiple charts for data available in single spread sheet like | # X Y Z | # * A 1 2 0 | * @ B 2 4 2 _|_@_ _ _ | A B similar to the above I have some more data in the same spreadsheet | # X1 Y1 Z1 | # * A 1 2 0 | * @ B 2 4 2 _|_@_ _ _ | A B I need to draw those charts using perl. I am using WriteExcel package to write that data in spreadsheet. Could anybody can help me to draw those charts.
Direct Responses: 5568 | Write a response
Posted on Fri Jun 29 10:46:31 2007 by jmcnamara in response to 5565
Re: Help with Multiple charts using chartex

Semi-automated response:

Hi,

Can you please post your question to the Spreadsheet::WriteExcel Google-Group.

http://groups.google.com/group/spreadsheet-writeexcel

Thank you,

John.
--
Write a response