Hi,
I'm trying to draw graphs in GD::Graph with some problems - I have two queries, the second of which produces the graph perfectly (for the last 39 days). The first query doesn't produce a graph. I can't see any difference (other than the number of rows returned - the second query doesn't if the number of rows are reduced either). Can anyone shed some light on the problem.
Thanks in advance,
Fraser
$sql = "SELECT TO_CHAR(TRUNC(OPENDATE), 'FMDD-MON'), COUNT(*) " .
"FROM ALARMLOG_HIST " .
"WHERE OPENDATE >= '1-AUG-2001' " .
"AND OPENDATE <= '31-AUG-2001' " .
"GROUP BY TRUNC(OPENDATE) " .
"ORDER BY TRUNC(OPENDATE) ASC";
$sql = "SELECT TO_CHAR(TRUNC(OPENDATE), 'FMDD-MON') AS ALARMDATE, COUNT(*) AS NUMALARMS FROM ALARMLOG_HIST GROUP BY TRUNC(OPENDATE)";
### set defaults
$chart = GD::Graph::bars->new(800,450);
@colors = [ qw(blue black green red) ];
$y_tick_number = 10;
$title = "Alarm No.";
$y_label = "Number of Alarms";
$sth = $dbh->prepare($sql)
or error(new CGI,'Cannot prepare query');
### execute SQL
$sth->execute() or error(new CGI,'Cannot execute query - ' . $sth->errstr());
### read data into graph datatype
my $data = GD::Graph:
ata->new();
my @row;
while (@row = $sth->fetchrow_array)
{
$data->add_point(@row) ;
### code to calculate maximum
...
}
### set max and round to suitable value
$max = ceil($indivMax/2000)*2000;
### finish with statement-handles
$sth->finish();
### disconnect
$dbh->disconnect();
### draw graph
$chart->set_legend_font(GD::gdSmallFont);
$chart->set_x_label_font(GD::gdMediumBoldFont);
$chart->set_y_label_font(GD::gdMediumBoldFont);
$chart->set(
fgclr => 'lgray',
'dclrs' => @colors,
borderclrs => @colors,
textclr => 'red',
x_label => 'Week Beginning',
x_label_position => 0.5,
x_labels_vertical => 1,
y_label => $y_label,
#title => $title,
y_max_value => $max,
y_min_value => 0,
y_long_ticks => 1,
y_tick_number => $y_tick_number,
y_label_skip => 2,
cumulate => 2,
bar_spacing => 4,
transparent => 0,
legend_placement => 'CC',
legend_marker_width => 20,
legend_marker_height => 15,
legend_spacing => 8,
t_margin => 15,
b_margin => 15,
l_margin => 15,
r_margin => 15,
);
print "Content-type: image/png\n\n";
binmode STDOUT;
print $chart->plot($data)->png();
exit;
I'm trying to draw graphs in GD::Graph with some problems - I have two queries, the second of which produces the graph perfectly (for the last 39 days). The first query doesn't produce a graph. I can't see any difference (other than the number of rows returned - the second query doesn't if the number of rows are reduced either). Can anyone shed some light on the problem.
Thanks in advance,
Fraser
$sql = "SELECT TO_CHAR(TRUNC(OPENDATE), 'FMDD-MON'), COUNT(*) " .
"FROM ALARMLOG_HIST " .
"WHERE OPENDATE >= '1-AUG-2001' " .
"AND OPENDATE <= '31-AUG-2001' " .
"GROUP BY TRUNC(OPENDATE) " .
"ORDER BY TRUNC(OPENDATE) ASC";
$sql = "SELECT TO_CHAR(TRUNC(OPENDATE), 'FMDD-MON') AS ALARMDATE, COUNT(*) AS NUMALARMS FROM ALARMLOG_HIST GROUP BY TRUNC(OPENDATE)";
### set defaults
$chart = GD::Graph::bars->new(800,450);
@colors = [ qw(blue black green red) ];
$y_tick_number = 10;
$title = "Alarm No.";
$y_label = "Number of Alarms";
$sth = $dbh->prepare($sql)
or error(new CGI,'Cannot prepare query');
### execute SQL
$sth->execute() or error(new CGI,'Cannot execute query - ' . $sth->errstr());
### read data into graph datatype
my $data = GD::Graph:
my @row;
while (@row = $sth->fetchrow_array)
{
$data->add_point(@row) ;
### code to calculate maximum
...
}
### set max and round to suitable value
$max = ceil($indivMax/2000)*2000;
### finish with statement-handles
$sth->finish();
### disconnect
$dbh->disconnect();
### draw graph
$chart->set_legend_font(GD::gdSmallFont);
$chart->set_x_label_font(GD::gdMediumBoldFont);
$chart->set_y_label_font(GD::gdMediumBoldFont);
$chart->set(
fgclr => 'lgray',
'dclrs' => @colors,
borderclrs => @colors,
textclr => 'red',
x_label => 'Week Beginning',
x_label_position => 0.5,
x_labels_vertical => 1,
y_label => $y_label,
#title => $title,
y_max_value => $max,
y_min_value => 0,
y_long_ticks => 1,
y_tick_number => $y_tick_number,
y_label_skip => 2,
cumulate => 2,
bar_spacing => 4,
transparent => 0,
legend_placement => 'CC',
legend_marker_width => 20,
legend_marker_height => 15,
legend_spacing => 8,
t_margin => 15,
b_margin => 15,
l_margin => 15,
r_margin => 15,
);
print "Content-type: image/png\n\n";
binmode STDOUT;
print $chart->plot($data)->png();
exit;