using hash to pass necessary values to GD Graph

K

kd

Hi..

First of all .. I would like the thank the ppl in this group who solved
my previous problem. Now I have another ..

I am trying to graph 4 series of data (00:00:00 06:00:00 12:00:00
18:00:00) using GD Graph.The each of them contain data for 3 6 9
...48(in increments of 3).

I want the graph to have something like the following:

series plot on graph
00:00:00 3 6 9 12 ....... 48
06:00:00 9 12 ....... 48 (skip the 1st 2 values)
12:00:00 15..... 48 (skip the 1st 4 values)
18:00:00 21.. 48 (skip the 1st 6 values)

The code I have written plots somthing like
series plot on graph
00:00:00 3 6 9 12 ....... 48
06:00:00 3 6 9 12 ....... 48
12:00:00 3 6 9 12 ....... 48
18:00:00 3 6 9 12 ....... 48

I would like to know a method to solve this.Thanks in advance.

-Karthik

#########################code########################

my %datahash;
my @xdata = ('3', '6', '9',
'12','15','18','21','24','27','30','33','36','39','42','45','48');
if ($tc=~m/wspeed/)
{
for my $var(qw(00:00:00 06:00:00 12:00:00 18:00:00))
{
my $date="$when"." $var";
my @data1;
my $sql5 = qq~SELECT u,v FROM $luse WHERE mid=$mval and
date_time='$date'~;
print "$sql5\n";
my $sth = $dbh->prepare($sql5);
$sth->execute;
while(my $uvdata=$sth->fetchrow_hashref)
{
my
@wstemp=sqrt($uvdata->{u}*$uvdata->{u}+$uvdata->{v}*$uvdata->{v})*2.2369;
my @wspeed;
push @wspeed,@wstemp;
foreach my $tval(@wspeed)
{
my $pval=sprintf("%.2f",$tval);
push @data1,$pval;
}
}
$datahash{$var}=\@data1;
}
}
my @data=(\@xdata);
for my $var(qw(00:00:00 06:00:00 12:00:00 18:00:00)){ push @data,
$datahash{$var}; }
my $gprint='Sliding Window Model Test';
my $mygraph = GD::Graph::lines->new(675,325);
$mygraph->set_legend_font(GD::gdSmallFont);
$mygraph->set_title_font(GD::gdSmallFont);
$mygraph->set_legend(' 00:00:00 ',' 06:00:00 ',' 12:00:00 ','
18:00:00 ');
$mygraph->set(
x_label => 'Forecast Hours (hours)',
y_label => $colnames{$tc},
two_axes =>1,
y_tick_number =>'auto',
x_long_ticks => 0,
y_tick_length => 1,
#y_long_ticks => 1,
title => $gprint,
line_types => [1, 1, 1, 1],
line_width => 2,
markers => [1, 1, 1, 1],
dclrs => ['blue','green','red','orange'],
bgclr => 'white',
fgclr => 'black',
textclr => 'black',
labelclr => 'black',
valuesclr => 'black',
axislabelclr => 'black',
legendclr => 'black',
legend_placement => 'TR',
transparent => 0,
types => 'linespoints',
) or warn $mygraph->error;
my $myimage = $mygraph->plot(\@data) or die $mygraph->error;
print "Content-type:image/png\n\n";
print $myimage->png;
#########################code########################
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top