Catalyst::View::SVG::TT::Graph - SVG::TT::Graph charts (in svg/png/gif/jpeg..) for your Catalyst application
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 => [ ... ] }, ];
Generate the SVG::TT::Graph chart
Note: These can be overridden by stashing parameters with the same name
Can be svg, png, gif, jpeg or any other format supported by Image::LibRSVG
A hashref that takes all options to SVG::TT::Graph::type . For the correct options, see the corresponding documentation:
Bar Options,
Pie Options,
Line Options,
BarLine Options,
TimeSeries Options,
BarHorizontal Options
An optional output format (svg/png/gif/jpeg..). Overrides config format
An optional title for your chart
Bar / Pie / Line / BarHorizontal / BarLine / TimeSeries
Any options taken by SVG::TT::Graph
A list (array reference) of fields to show in your graph:
$c->stash->{fields} = [ 'Jan', 'Feb', 'March' .. ];
If all you want is a singe data set, can be a hash reference of the form:
$c->stash->{chart_data} = { title => 'sales', values => [ 1.4, 2.2, ... ] }
or a simple ArrayRef if you don't want a title
$c->stash->{chart_data} = [ 1.4, 2.2, ... ]
If you want multiple data sets, use an array reference with each set in a hashref:
$c->stash->{chart_data} = [ { title => 'Barcelona', data => [ .. ] }, { title => 'Atletico', data => [ .. ] } ];
See http://leo.cuckoo.org/projects/SVG-TT-Graph/
For jpeg pie charts, background color transparency doesn't work
See git://github.com/terencemo/Catalyst--View--SVG--TT--Graph.git
SVG::TT::Graph, Image::LibRSVG
Terence Monteiro <terencemo[at]cpan.org>
This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.
To install Catalyst::View::SVG::TT::Graph, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::View::SVG::TT::Graph
CPAN shell
perl -MCPAN -e shell install Catalyst::View::SVG::TT::Graph
For more information on module installation, please visit the detailed CPAN module installation guide.