ag4ve has asked for the wisdom of the Perl Monks concerning the following question:

i'm having issues with the line names and values given for the x-axis. i have this code:

sub chart_me { my( $row, $name ) = @_; my $chart = $workbookout->add_chart( type => 'line', name => $name +); $chart->set_title( name => $name ); foreach my $i ( 1 .. 6 ) { my $rowi = $row + $i - 1; $chart->add_series( name => $header[ $i ], catagories => xl_range_formula( 'Sheet1', 1, 1, 2, $ma +xcol ), values => xl_range_formula( 'Sheet1', $rowi, $rowi +, 2, $maxcol ), ); } }

which generally works. my issue is that the value for 'name' should come from an array and instead is giving me "Row 2", "Row 3", etc. ie, "Row ".$i also, i can't find a way to get the values for the x-axis to be named as the date they come from (row 1) - i've got data from 2009-01 to 2010-12 and i'm getting 1 .. 24. is there any way to do this?

UPDATE

i did have some off by one issues, but correcting them just means that the data is fitting correctly in the graph - it didn't solve any of my issues.
$chart->add_series( name => $header[ $i ], catagories => xl_range_formula( 'Sheet1', 0, 0, 1, $ma +xcol ), values => xl_range_formula( 'Sheet1', $rowi, $rowi +, 1, $maxcol ), );

UPDATE #2

i figured out that the 'name' for each line is actually given by the 'name_format' value. i'm now not entirely sure what 'name' is for. i plan to keep playing with it, and see if i can get some better / interesting results to pop out. my current add_series object definition looks like:

$chart->add_series( name => $header[ $i ], name_formula => '=Sheet1!' . xl_rowcol_to_cell( $rowi +, 0, 1, 1 ), catagories => xl_range_formula( 'Sheet1', 0, 0, 1, +$maxcol ), values => xl_range_formula( 'Sheet1', $rowi, $r +owi, 1, $maxcol ), );

Replies are listed 'Best First'.
Re: Help with Spreadsheet::WriteExcel::Chart
by tilly (Archbishop) on Jan 24, 2011 at 06:35 UTC
    Is it possible that what you think should be set by the name is instead being set by categories? What is x1_range_formula?

      i suppose categories was my other question. i'm pretty sure i get what these functions are supposed to do and per the example here: http://search.cpan.org/dist/Spreadsheet-WriteExcel/lib/Spreadsheet/WriteExcel/Examples.pm#Example:_chart_stock.pl it should be possible to do what i want. i'm obviously just doing something wrong :) neither is being set to what i want. my spreadsheet looks like this

      x | date 1 | date 2 | date 3 | name | | | | data 1 | #### | #### | #### | data 2 | #### | #### | #### | data 3 | #### | #### | #### | | | | | name2 | | | | data 1 | #### | #### | #### | etc

      Spreadsheet::WriteExcel::Utility::xl_range_formula()

Re: Help with Spreadsheet::WriteExcel::Chart
by Khen1950fx (Canon) on Jan 24, 2011 at 14:32 UTC
    This will help:
    #!/usr/bin/perl use strict; use warnings; use Spreadsheet::WriteExcel; use Spreadsheet::WriteExcel::Utility; my( $row, $name ) = @_; my $workbook = Spreadsheet::WriteExcel->new('chart.xls'); my $worksheet = $workbook->add_worksheet(); my $chart = $workbook->add_chart( type => 'line' ); $chart->set_title( name => $name ); foreach my $i ( 1 .. 6 ) { my $rowi; my $maxcol; $chart->add_series( name => my $header, catagories => xl_range_formula( 'Sheet1', 1, 1, 2, $maxcol ) +, values => xl_range_formula( 'Sheet1', $rowi, $rowi, 2, $ +maxcol ), ); }

      how does that help? i mean, what am i doing wrong? why would i set an undefined $rowi or an undefined $maxcol as the row and column i want to get values from? why would i set an undefined $header as an attribute to name?

      i'm sure in abstracting the code, you're implying something i'm just not seeing. however, what am i missing here?