Tk::Chart::Pie - Extension of Canvas widget to create a pie graph. |
Tk::Chart::Pie - Extension of Canvas widget to create a pie graph.
Tk::Chart::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.
You can set a background gradient color.
When the mouse cursor passes over a pie slice or its entry in the legend, the pie slice 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).
You can set a background gradient color by using all methods of the Tk::Canvas::GradientColor manpage. By default, it is not enabled.
To enabled background gradient color the first time, you firstly have to call enabled_gradientcolor method and configure your color and type of gradient with set_gradientcolor.
$chart->enabled_gradientcolor(); $chart->set_gradientcolor( -start_color => '#6585ED', -end_color => '#FFFFFF', );
Please, read WIDGET-SPECIFIC METHODS in the Tk::Canvas::GradientColor manpage documentation to know all available configurations.
#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::Chart::Pie; my $mw = MainWindow->new( -title => 'Tk::Chart::Pie example', ); my $chart = $mw->Pie( -title => 'Registered public CPAN countries sites' . "\n" . 'around the World (266 sites, 61 countries in 19 July 2011)', -background => 'white', -linewidth => 2, )->pack(qw / -fill both -expand 1 /); my @data = ( [ 'Africa', 'Asia', 'Central America', 'Europe', 'North America', 'Oceania', 'South America' ], [ 2, 16, 1, 32, 3, 3, 4 ], ); $chart->plot( \@data ); MainLoop();
-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
Many options allow you to configure your graph as you want. The default configuration is already OK, but you can change it.
-title => 'My pie graph title',
Default : undef
-titleposition => 'left',
Default : center
-titlecolor => 'red',
Default : black
-titlefont => 'Times 15 {normal}',
Default : {Times} 12 {bold}
-titleheight => 100,
Default : 40
-linewidth => 10,
Default : 1
-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).
-piesize => 180, # Pie graph will be display in a half circle
Default : 360
-startangle => 90,
Default : 0
-verbose => 0,
Default : 1
-legendcolor => 'white',
Default : 'black'
-legendfont => '{Arial} 8 {normal}',
Default : {Times} 8 {normal}
-setlegend => 0,
Default : 1
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.
$chart->disabled_automatic_redraw;
$chart->enabled_automatic_redraw;
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::Chart::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 ], ); $pie_chart->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 the graph.
If you have used clearchart for any reason, it is possible to redraw the graph. Tk::Chart::Pie supports the configure and cget methods described in the the Tk::options manpage manpage. If you use configure method to change a widget specific option, the modification will not be display. If the graph was already displayed and if you not resize the widget, call redraw method to resolv the bug.
... $mw->Button( -text => 'Change title', -command => sub { $pie_chart->configure(-title => 'other title'); }, )->pack; ... # title will be changed but not displayed if you not resize the widget. ... $mw->Button( -text => 'Change title', -command => sub { $pie_chart->configure(-title => 'other title'); $pie_chart->redraw; } )->pack; ... # OK, title will be changed and displayed without resize the widget.
$pie_chart->zoom(integer);
Zoom the graph (vertical and horizontal zoom).
Ex : 300*300 size $pie_chart->zoom(50); # size divide by 2 => 150*150 ... $pie_chart->zoom(200); # size multiplie by 2 => 600*600 ... $pie_chart->zoom(120); # 20% add in each axis => 360*360 ... $pie_chart->zoom(100); # original resize 300*300.
Horizontal zoom.
# original canvas size 300*300 $pie_chart->zoomx(50); # new size : 150*300 ... $pie_chart->zoom(100); # new size : 300*300
Vertical zoom.
# original canvas size 300*300 $pie_chart->zoomy(50); # new size : 300*150 ... $pie_chart->zoom(100); # new size : 300*300
In the demo directory, you have a lot of script examples with their screenshot. See also the http://search.cpan.org/dist/Tk-Chart/MANIFEST web page of the Tk::Chart manpage.
See the Tk::Canvas manpage for details of the standard options.
See the Tk::Chart manpage, the Tk::Chart::FAQ manpage, the GD::Graph manpage.
Djibril Ousmanou, <djibel at cpan.org>
Please report any bugs or feature requests to bug-tk-chart at rt.cpan.org
, or through
the web interface at http://rt.cpan.org/NoAuth/ReportBug.html. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc Tk::Chart::Pie
You can also look for information at:
Copyright 2011 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.
Tk::Chart::Pie - Extension of Canvas widget to create a pie graph. |