Click here to get back home

combining graphs from GD::Graph in one image file

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
combining graphs from GD::Graph in one image file tospo 05-28-2006
Posted by tospo on May 28, 2006, 9:51 am
Please log in for more thread options


Does anybody know how I can get more than one graph on a single image
file generated by the GD:Graph module?

I need to generate a lot of histograms which cannot be combined into a
single chart but all of these charts should be combined into one big
image file (doesn't need to be pretty). I need to make a lot of these
so combining the images by hand would not be ideal - is there a way to
do this in GD:Graph?

Thanks a lot!


Posted by Dr.Ruud on May 29, 2006, 6:33 am
Please log in for more thread options


tospo schreef:

> Does anybody know how I can get more than one graph on a single image
> file generated by the GD:Graph module?

Is that a real question? I don't think so. Please read
http://www.catb.org/~esr/faqs/smart-questions.html


> I need to generate a lot of histograms which cannot be combined into a
> single chart

Why not?


> but all of these charts should be combined into one big
> image file (doesn't need to be pretty).

What is your definition of 'combined'? For 'not pretty' you could put
them all transparently on top of each other.


> I need to make a lot of these
> so combining the images by hand would not be ideal - is there a way to
> do this in GD:Graph?

I think you mean GD::Graph. I would use the module GD to do this.

--
Affijn, Ruud

"Gewoon is een tijger."



Posted by tospo on May 29, 2006, 8:15 am
Please log in for more thread options


Apologies if this was unclear and sorry for the typo.

I cannot combine all of my histograms for one dataset into one chart
because there will be dozens of them and the output will not be
readable.

By "not pretty" I meant that it doesn't have to be formatted for
printing or anything. It is fine if this generates a big image that one
needs to scroll through on a computer screen because that's all that I
want to do with it.

So what I want the output of my script to look like is this:

chart 1 chart 2
| |
+------ +---------

chart 3 chart 4
| |
+------ +----------

I couldn't find anything on the internet that shows me how (and if)
this can be done in GD::Graph.

How would I do this with GD?

Thank you very much for your help,

tospo


Posted by Peter Scott on May 29, 2006, 10:29 am
Please log in for more thread options


On Mon, 29 May 2006 05:15:25 -0700, tospo wrote:
> By "not pretty" I meant that it doesn't have to be formatted for
> printing or anything. It is fine if this generates a big image that one
> needs to scroll through on a computer screen because that's all that I
> want to do with it.

http://www.imagemagick.org/script/perl-magick.php#montage

--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/


Posted by Dean Arnold on May 29, 2006, 10:43 am
Please log in for more thread options


tospo wrote:
> Apologies if this was unclear and sorry for the typo.
>
> I cannot combine all of my histograms for one dataset into one chart
> because there will be dozens of them and the output will not be
> readable.
>
> By "not pretty" I meant that it doesn't have to be formatted for
> printing or anything. It is fine if this generates a big image that one
> needs to scroll through on a computer screen because that's all that I
> want to do with it.
>
> So what I want the output of my script to look like is this:
>
> chart 1 chart 2
> | |
> +------ +---------
>
> chart 3 chart 4
> | |
> +------ +----------
>
> I couldn't find anything on the internet that shows me how (and if)
> this can be done in GD::Graph.
>
> How would I do this with GD?
>

I think the terms you're (collectively) searching for are
"composite" vs. "tiled", ie, composite mashes all the
charts into a single set of axes; tiled is what is described above.

That said, AFAIK, GD::Graph doesn't directly support tiling;
however, implementing it directly in GD should be pretty
straightforward.

1. Create each chart as a standalone image.

2. Compute the size needed to contain the charts as tiles

3. Create a new GD::Image

4. Copy each chart image into the tiled image at the proper
coordinates

E.g., if all are same size, then (psuedocode):

#
#        create charts here as usual, pushing each resulting
#        GD::Image object on @charts
#
$Htiled = $Hchart * 2 + $vmargin;        # height + some vertical margin
$Wtiled = $Wchart * 2 + $hmargin;        # width + some horiz. margin

my $tiled = new GD::Image($Wtiled, $Htiled);
my $white = $tiled->colorAllocate(255, 255, 255);
#
#        fill the background
#
$tiled->filledRectangle(0,0,$Wtiled-1, $Htiled-1, $white);
#
#        compute coords of each tiled chart
#        NOTE: these need adjustment for the margin spacing
#
my @coords = (
        0, 0,
        $Wtiled/2, 0,
        0, $Htiled/2,
        $Wtiled/2, $Htiled/2
);

$tiled->copy($_, shift @corrds, shift @coords, 0,0,$Wchart,$Hchart)
        foreach (@charts);

open TILED, ">$tiled_file";
binmode TILED;
print TILED $tiled->png();
close TILED;


HTH,
Dean Arnold
Presicient Corp.

Similar ThreadsPosted
GD::Graph with Image Map implementation question June 27, 2007, 3:10 pm
GD::Graph - how to get rid of leading gap in line graph? October 1, 2004, 10:56 am
Graph.0.69 Module---how to get a DAG from graph with cycles January 23, 2006, 2:50 pm
Combining HTTP:Daemon and CGI May 27, 2006, 5:07 pm
GD::GRAPH two_axes December 8, 2004, 6:01 pm
GD::Graph isn't numeric etc. January 26, 2005, 7:43 pm
GD graph, Several Colors per Bar? May 30, 2005, 6:52 pm
Name for a new Tk Graph module April 4, 2007, 6:17 am
Perl GD::Graph module: bug? August 3, 2004, 8:42 pm
GD::Graph => How to set maximum value manually on Y ? October 6, 2004, 6:35 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap