Re: combining graphs from GD::Graph in one image file



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.
.



Relevant Pages

  • Histogram Invalid Reference
    ... histograms. ... execution after the first chart is made. ... I pass 3 ranges to the histogram generation code...1) HistData - range ... 'Bin Range ...
    (microsoft.public.excel.programming)
  • trouble with pasting in Excel charts, canvases, and converting to
    ... I use ReWorx 2003 Professional to convert the Word files. ... set of text in the chart: the legend or the axis labels, ... charts, dozens of files--and clearly, shouldn't be necessary! ...
    (microsoft.public.word.drawing.graphics)
  • Re: combining graphs from GD::Graph in one image file
    ... Apologies if this was unclear and sorry for the typo. ... I cannot combine all of my histograms for one dataset into one chart ...
    (comp.lang.perl.modules)
  • Chart for System.Drawing.Color
    ... Have you ever wondered what the colors are of those dozens of colors ... I ran across this nice chart that shows color patches of all of them: ... and then using RGB(rValue, gValue, bValue) in VB. ...
    (microsoft.public.dotnet.languages.vb)