wizsc has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks, I'm trying to plot a chart in perl from the excel sheet that I also create in the program. Below is the actual code. If I understood it correctly, the $A and $B etc under "values" in add_series function are the excel column number. I'm facing a problem where it would plot data only if I put $A in it. No other column(tried $B, $CJ). I'll appreciate help with these questions: 1. Why is nothing being plotted if I try any column other than $A? 2. I need to automate it to pick the last column of any sheet. I couldn't figure a syntax to do that. 3. How do I automate the worksheet name “sim_*” to as many sheets I have?
#!/usr/intel/pkgs/perl/5.14.1/bin/perl use Spreadsheet::WriteExcel; $num_files = @ARGV[0]; print "Help - Syntax: ./process_xyz.pl <number_of_csv_files> <all_csv_files>\n"; print " The output file is: xyz_stat.xls \n"; my $workbook = Spreadsheet::WriteExcel->new('xyz_stat.x +ls') or die $!; my $worksheet_chart = $workbook->add_worksheet('chart'); my $chart = $workbook->add_chart(type => 'line', emb +edded => 1); for ($k = 1; $k <= $num_files; $k++) { $stat_file[$k] = @ARGV[$k]; open (_file, "$stat_file[$k]") or die "cannot open $stat_file[$k]"; $frm_num = 0; $frm_start = 2; $frm_end = 3; $tmp_var = "sim_$k"; $worksheet[$k] = $workbook->add_worksheet($tmp_var); while ($line = <_file>) { @frame_stats = split(/,/,$line); my $col = 0; foreach $el(@frame_stats) { $worksheet[$k]->write($frm_num, $col, $el); $col ++; } $frm_num++; } } $chart->add_series( # categories => '=test1!$A$2:$A$10', values => '=sim_1!$B$2:$B$361', # values => '=sim_1!$A$2:$A$361', name => 'sim1', ); $chart->add_series( # categories => '=test1!$A$2:$A$10', values => '=sim_2!$CU$2:$CU$361', name => 'sim2', ); $worksheet_chart->insert_chart('E2', $chart, 15, 10);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Plot a chart
by 1s44c (Scribe) on Jul 22, 2014 at 23:06 UTC | |
by wizsc (Initiate) on Jul 22, 2014 at 23:43 UTC | |
|
Re: Plot a chart
by poj (Abbot) on Jul 23, 2014 at 18:59 UTC | |
by wizsc (Initiate) on Jul 23, 2014 at 22:05 UTC | |
by poj (Abbot) on Jul 24, 2014 at 09:44 UTC | |
by wizsc (Initiate) on Jul 24, 2014 at 23:37 UTC |