Catalyst-View-SVG-TT-Graph

 view release on metacpan or  search on metacpan

lib/Catalyst/View/SVG/TT/Graph.pm  view on Meta::CPAN

package Catalyst::View::SVG::TT::Graph;

use Moose;
BEGIN { extends 'Catalyst::View'; }

use Carp;
use Image::LibRSVG;
use MIME::Types;

our $VERSION = 0.0226;

has 'format' => ( is => 'ro', isa => 'Str', default => 'svg' );

has 'chart_conf' => ( is => 'ro', isa => 'HashRef', default => sub {{}} );

has 't' => ( is => 'ro', isa => 'MIME::Types', default => sub { MIME::Types->new } );

=head1 NAME

Catalyst::View::SVG::TT::Graph - SVG::TT::Graph charts (in svg/png/gif/jpeg..) for your Catalyst application

=head1 SYNOPSIS

Create your view class:

    ./script/myapp_create.pl view Chart SVG::TT::Graph

Set your chart preferences in your config:

    <View::Chart>
        format         png
        <chart_conf>
            style_sheet         /path/to/stylesheet.css
            show_graph_title    1
        </chart_conf>
    </View::Chart>

Stash your chart data in your controller:

    $c->stash->{chart_title} = 'Sales data'; # optional
    
    $c->stash->{chart_type} = 'Bar'; # or Pie/Line/BarHorizontal
    
    $c->stash->{chart_conf} = {
        height  => 400,
        width   => 600
    };
    
    $c->stash->{chart_fields} = [ qw(Jan Feb March ..) ];
    $c->stash->{chart_data} = [ 120, 102, ..];

In your end method:

    $c->forward($c->view('Chart'));

If you want, say a comparative line graph of mutiple sets of data:

    $c->stash->{chart_type} = 'Line';
    
    $c->stash->{chart_data} = [
        { title => 'Barcelona', data => [ ... ] },
        { title => 'Atletico', data => [ ... ] },
    ];

=cut

=head1 METHODS

=head2 process

Generate the SVG::TT::Graph chart

=cut



( run in 2.275 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )