++ed by:

1 non-PAUSE user.

Leo Lapworth


SVG::TT::Graph - Base object for generating SVG Graphs


  package SVG::TT::Graph::GRAPH_TYPE
  use SVG::TT::Graph;
  use base qw(SVG::TT::Graph);

  sub _set_defaults {
    my $self = shift;

    my %default = (
        'keys'  => 'value',
    while( my ($key,$value) = each %default ) {
      $self->{config}->{$key} = $value;

  sub get_template {
    my $self = shift;
    # read in template
    my $template = 'set the template';
    return $template;
  # optional - called when object is created
  sub _init {
    my $self = shift;
        # any testing you want to do.
  In your script...
  use SVG::TT::Graph::GRAPH_TYPE;
  my $width = '500',
  my $heigh = '300',
  my @fields = qw(field_1 field_2 field_3);
  my $graph = SVG::TT::Graph::GRAPH_TYPE->new({
    # Required for some graph types
    'fields'           => \@fields,
    # .. other config options
    'height' => '500',
  my @data = qw(23 56 32);
        'data' => \@data,
        'title' => 'Sales 2002',
  # find a config options value
  my $config_value = $graph->config_option();
  # set a config option value
  # All graphs support SVGZ (compressed SVG) if 
  # Compress::Zlib is available.
  # either 'compress' => 1 config option, or
  print "Content-type: image/svg+xml\r\n";
  print $graph->burn();


This package should be used as a base for creating SVG graphs.

See SVG::TT::Graph::Line for an example.



  my @data_sales_02 = qw(12 45 21);

    'data' => \@data_sales_02,
    'title' => 'Sales 2002',

This method allows you do add data to the graph object. It can be called several times to add more data sets in.


  my $graph->clear_data();

This method removes all data from the object so that you can reuse it to create a new graph but with the same config options.


  print $graph->burn();

This method processes the template with the data and config which has been set and returns the resulting SVG.

This method will croak unless at least one data set has been added to the graph object.

config methods

  my $value = $graph->method();

This object provides autoload methods for all config options defined in the _set_default method within the inheriting object.

See the SVG::TT::Graph::GRAPH_TYPE documentation for a list.


For examples look at the project home page http://leo.cuckoo.org/projects/SVG-TT-Graph/


None by default.


Thanks to Foxtons for letting us put this on CPAN. Todd Caine for heads up on reparsing the template (but not using atm) David Meibusch for TimeSeries and a load of other ideas


Leo Lapworth (LLAP@cuckoo.org) and Stephen Morgan (TT and SVG)


SVG::TT::Graph::Line, SVG::TT::Graph::Bar, SVG::TT::Graph::BarHorizontal, SVG::TT::Graph::BarLine, SVG::TT::Graph::Pie, SVG::TT::Graph::TimeSeries, Compress::Zlib,


Copyright (C) 2003, Leo Lapworth

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