NAME
Tk::ForDummies::Graph::Pie - Extension of Canvas widget to create a pie chart.
DESCRIPTION
Tk::ForDummies::Graph::Pie is an extension of the Canvas widget. It is an easy way to build an interactive pie graph into your Perl Tk widget. The module is written entirely in Perl/Tk.
When the mouse cursor passes over a pieslice or its entry in the legend, the pieslice turn to a color (that you can change) and a balloon box display to help identify it.
You can use 3 methods to zoom (vertically, horizontally or both).
SYNOPSIS
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
use Tk::ForDummies::Graph::Pie;
my $mw = new MainWindow( -title => 'Tk::ForDummies::Graph::Pie example', );
my $GraphDummies = $mw->Pie(
-title => 'CPAN mirrors around the World',
-background => 'white',
-linewidth => 2,
)->pack(qw / -fill both -expand 1 /);
my @data = (
[ 'Europe', 'Asia', 'Africa', 'Oceania', 'Americas' ],
[ 97, 33, 3, 6, 61 ],
);
$GraphDummies->plot( \@data );
MainLoop();
STANDARD OPTIONS
-background -borderwidth -closeenough -confine -cursor -height -highlightbackground -highlightcolor -highlightthickness -insertbackground -insertborderwidth -insertofftime -insertontime -insertwidth -relief -scrollregion -selectbackground -selectborderwidth -selectforeground -takefocus -width -xscrollcommand -xscrollincrement -yscrollcommand -yscrollincrement
WIDGET-SPECIFIC OPTIONS
Many options allow you to configure your chart as you want. The default configuration is already OK, but you can change it.
- Name: Title
- Class: Title
- Switch: -title
-
Title of your graph.
-title => "My pie graph title",
Default : undef
- Name: Titlecolor
- Class: TitleColor
- Switch: -titlecolor
-
Title color of your graph.
-titlecolor => "red",
Default : black
- Name: Titlefont
- Class: TitleFont
- Switch: -titlefont
-
Set the font for the title text. See also textfont option.
-titlefont => "Times 15 {normal}",
Default : {Times} 12 {bold}
- Name: Titleheight
- Class: TitleHeight
- Switch: -titleheight
-
Height for title graph space.
-titleheight => 100,
Default : 40
- Name: Linewidth
- Class: LineWidth
- Switch: -linewidth
-
Set width of all lines slice pie inthe chart.
-linewidth => 10,
Default : 1
- Name: Colordata
- Class: ColorData
- Switch: -colordata
-
This controls the colors of the lines. This should be a reference to an array of color names.
-colordata => [ qw(green pink blue cyan) ],
Default :
[ 'red', 'green', 'blue', 'yellow', 'purple', 'cyan', '#996600', '#99A6CC', '#669933', '#929292', '#006600', '#FFE100', '#00A6FF', '#009060', '#B000E0', '#A08000', 'orange', 'brown', 'black', '#FFCCFF', '#99CCFF', '#FF00CC', '#FF8000', '#006090', ],
The default array contain 24 colors. If you have more than 24 samples, the next line will have the color of the first array case (red).
- Name: Startangle
- Class: StartAngle
- Switch: -startangle
-
The angle at which the first data slice will be displayed, with 0 degrees being "3 o'clock".
-startangle => 90,
Default : 0
WIDGET METHODS
The Canvas method creates a widget object. This object supports the configure and cget methods described in Tk::options which can be used to enquire and modify the options described above.
clearchart
- $PieGraphDummies->clearchart
-
This method allows you to clear the chart. The canvas will not be destroy. It's possible to redraw your last chart using the redraw method.
plot
\@data
Fill an array of arrays with the legend values and the values of the datasets (\@data). Make sure that every array have the same size, otherwise Tk::ForDummies::Graph::Pie will complain and refuse to compile the graph.
my @data = ( [ '1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th' ], [ 1, 2, 52, 6, 3, 17.5, 1, 43, 10 ] );
@data have to contain two arrays, the legend values and the values of the datasets.
If you don't have a value for a point in a dataset, you can use undef, and the point will be skipped.
[ 1, undef, 5, 6, 3, 1.5, undef, 3, 4 ]
-substitutionvalue => real number,
If you have a no real number value in a dataset, it will be replaced by a constant value.
Default : 0
my @data = ( [ '1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th' ], [ 1, "--", 5, 6, 3, 1.5, 1, 3, 4 ], ); $PieGraphDummies->plot( \@data, -substitutionvalue => '12', ); # mistake, -- and NA will be replace by 12
-substitutionvalue have to be a real number (ex : 12, .25, 02.25, 5.2e+11, etc ...)
redraw
Redraw the chart.
If you have used clearchart for any reason, it is possible to redraw the chart. Tk::ForDummies::Graph::Pie supports the configure and cget methods described in the Tk::options manpage. If you use configure method to change a widget specific option, the modification will not be display. If the chart was already displayed and if you not resize the widget, call redraw method to resolv the bug.
...
$fenetre->Button(-text => "Change title", -command => sub {
$PieGraphDummies->configure(-title => "other title");
}
)->pack;
...
# title will be changed but not displayed if you not resize the widget.
...
$fenetre->Button(-text => "Change title", -command => sub {
$PieGraphDummies->configure(-title => "other title");
$PieGraphDummies->redraw;
}
)->pack;
...
# OK, title will be changed and displayed without resize the widget.
zoom
zoom the chart (vertical and horizontal zoom).
$PieGraphDummies->zoom($zoom);
$zoom must be an integer great than 0.
Ex : 300*300 size
$PieGraphDummies->zoom(50); # size divide by 2 => 150*150
...
$PieGraphDummies->zoom(200); # size multiplie by 2 => 600*600
...
$PieGraphDummies->zoom(120); # 20% add in each axis => 360*360
...
$PieGraphDummies->zoom(100); # original resize 300*300.
zoomx
Horizontal zoom.
# original canvas size 300*300
$PieGraphDummies->zoomx(50); # new size : 150*300
...
$PieGraphDummies->zoom(100); # new size : 300*300
zoomy
Vertical zoom.
# original canvas size 300*300
$PieGraphDummies->zoomy(50); # new size : 300*150
...
$PieGraphDummies->zoom(100); # new size : 300*300
SEE ALSO
See Tk::Canvas for details of the standard options.
See Tk::ForDummies::Graph, Tk::ForDummies::Graph::FAQ, GD::Graph.
AUTHOR
Djibril Ousmanou, <djibel at cpan.org>
BUGS
Please report any bugs or feature requests to bug-tk-fordummies-graph at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Tk-ForDummies-Graph. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Tk::ForDummies::Graph::Pie
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Tk-ForDummies-Graph
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
COPYRIGHT & LICENSE
Copyright 2009 Djibril Ousmanou, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.