Rob Kinyon


Graph::Template - Graph::Template


First, make a template. This is an XML file, describing the layout of the spreadsheet.

For example, test.xml:

      <title text="Testing Title"/>
      <xlabel text="X Label"/>
      <ylabel text="Y Label"/>
      <data name="test_data">
          <datapoint value="$x_point"/>
          <datapoint value="$y_point"/>

Now, create a small program to use it:

  #!/usr/bin/perl -w
  use Graph::Template

  # Create the Graph template
  my $template = Graph::Template->new(
      filename => 'test.xml',

  my @data;
  for (1 .. 3)
      push @data, {
          x_point => $_,
          y_point => 4 - $_,

  # Add a few parameters
      test_data => \@data,


If everything worked, then you should have a graph in your work directory called test.png that looks something like:

           Testing Title
  5 +-------------------------+
    |                         |
    |                         |
  4 +                         |
    |                         |
    |                         |
  3 +   +-----+               |
    |   |     |               |
    |   |     |               |
  2 +   |     |-----+         |
    |   |     |     |         |
    |   |     |     |         |
  1 +   |     |     |-----+   |
    |   |     |     |     |   |
    |   |     |     |     |   |
  0 +---+-----+-----+-----+---+
           1     2     3


This is a module used for templating Graph files. Its genesis came from the need to use the same datastructure as HTML::Template, but provide Graph files instead. The existing modules don't do the trick, as they require separate logic from what HTML::Template needs.

Currently, only a small subset of the planned features are supported. This is meant to be a test of the waters, to see what features people actually want.


I do a lot of Perl/CGI for reporting purposes. Usually, I've been asked for HTML, PDF, and Excel. Recently, I've been asked to do graphs, using the exact same data. Instead of writing graphing-specific code, I preferred to do it once in a template.



This creates a Graph::Template object. If passed a filename parameter, it will parse the template in the given file. (You can also use the parse() method, described below.)


This method is exactly like HTML::Template's param() method. Although, I will be adding more to this section later, please see HTML::Template's description for info right now.

parse() / parse_xml()

This method actually parses the template file. It can either be called separately or through the new() call. It will die() if it cannot handle any situation.


Create the Graph file and write it to the specified filename. This is when the actual merging of the template and the parameters occurs.


It will act just like HTML::Template's output() method, returning the resultant file as a stream, usually for output to the web.


This is just a list of nodes. See the other classes in for more details on specific parameters and the like.




  • DATA



None, that I know of. (But there aren't many features, neither!)


This is currently beta-quality software. It's built on the new PDF::Template technology, which was just released. The featureset is extremely limited, but I expect to be adding on to it very soon.


    Rob Kinyon


This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.


perl(1), HTML::Template, GD::Graph, GD.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 313:

=back doesn't take any parameters, but you said =back 4