[ABE.pm] "Rotating" a table
Faber J. Fedor
faber at linuxnj.com
Thu Dec 21 14:19:24 PST 2006
I'm using this (so far) awesome graphics package called ChartDirector
(http://www.advsofteng.com/). It's not FLOSS but I haven't found
anything that will do as much as CD in as little time.
Anywho, to make my plots, ChartDirector likes arrays refs. To plot my
two sets of x data data with labels I would create the arrayrefs like
this:
my $data1 = [ 1,2,3,4,5];
my $data2 = [ 6,7,8,9,10];
my $labels = ['Jan', 'Feb', 'Mar', 'Apr', 'May'];
(This is how they do it in the sample code.)
The data I'm plotting is in a table that looks like this:
year, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10
What I need to do is to put all the years in one arrayref, all the d1s
in another array ref, the d2' in an arrayref, etc. For ease of coding, I
should prolly put all of those arrayrefs into another arrayref.
What is a good method to "rotate" the table?
In my "proof of concept" code I did this:
my $dataHRef = $rptDBH->selectall_hashref($stmt, 'year');
foreach my $date (sort keys %$dataHRef) {
push(@labels, $date);
push(@Decile1, %$dataHRef->{$date}->{'d1'});
push(@Decile2, %$dataHRef->{$date}->{'d2'});
push(@Decile3, %$dataHRef->{$date}->{'d3'});
push(@Decile4, %$dataHRef->{$date}->{'d4'});
push(@Decile5, %$dataHRef->{$date}->{'d5'});
push(@Decile6, %$dataHRef->{$date}->{'d6'});
push(@Decile7, %$dataHRef->{$date}->{'d7'});
push(@Decile8, %$dataHRef->{$date}->{'d8'});
push(@Decile9, %$dataHRef->{$date}->{'d9'});
push(@Decile10, %$dataHRef->{$date}->{'d10'});
}
Which is kinda lame, you must admit. The date ordering is very
important.
Any suggestion to make this code less lame and independent of the number
'10'? I may have five or or fifteen data sets to plot.
--
Regards,
Faber Fedor
President
Linux New Jersey, Inc.
908-320-0357
800-706-0701
http://www.linuxnj.com
More information about the ABE-pm
mailing list