Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GD::Graph

Status
Not open for further replies.

frasernm

Programmer
Aug 7, 2001
25
GB
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' " .
&quot;AND OPENDATE <= '31-AUG-2001' &quot; .
&quot;GROUP BY TRUNC(OPENDATE) &quot; .
&quot;ORDER BY TRUNC(OPENDATE) ASC&quot;;

$sql = &quot;SELECT TO_CHAR(TRUNC(OPENDATE), 'FMDD-MON') AS ALARMDATE, COUNT(*) AS NUMALARMS FROM ALARMLOG_HIST GROUP BY TRUNC(OPENDATE)&quot;;

### set defaults
$chart = GD::Graph::bars->new(800,450);
@colors = [ qw(blue black green red) ];
$y_tick_number = 10;
$title = &quot;Alarm No.&quot;;
$y_label = &quot;Number of Alarms&quot;;

$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::Data->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 &quot;Content-type: image/png\n\n&quot;;
binmode STDOUT;
print $chart->plot($data)->png();

exit;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top