I can't be certain, but I suspect the problem is in the last print statement you show. print $my_graph->plot(\@data)->$format(); The plot function returns a GD object, for example:
my $gd = graph->plot(...);
my $format = $my_graph->export_format;
print header("image/$format");
binmode STDOUT;
print $gd->gif;