View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Dr Bean > Tk-ForDummies-Graph-1.11 > Tk::ForDummies::Graph::Pie



Annotate this POD

View/Report Bugs
Module Version: 1.06   Source   Latest Release: Tk-ForDummies-Graph-1.14


Tk::ForDummies::Graph::Pie - Extension of Canvas widget to create a pie graph.


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 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).


  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 );



-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.

Name: Title
Class: Title
Switch: -title

Title of your graph.

 -title => 'My pie graph title',

Default : undef

Name: Titleposition
Class: TitlePosition
Switch: -titleposition

Position of title : center, left or right

 -titleposition => 'left',

Default : center

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 graph.

 -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


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.



When the graph is created and the widget size changes, the graph is automatically re-created. Call this method to avoid resizing.




Use this method to allow your graph to be recreated automatically when the widget size change. When the graph is created for the first time, this method is called.




This method allows you to clear the graph. The canvas will not be destroy. It's possible to redraw your last graph using the redraw method.


$PieGraphDummies->plot(\@data, ?arg)

Use this method to create your pie graph.


Redraw the graph.

If you have used clearchart for any reason, it is possible to redraw the graph. 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 graph 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'); 
 # 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'); 
 # OK, title will be changed and displayed without resize the widget.


zoom the graph (vertical and horizontal 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. 


Horizontal zoom.

 # original canvas size 300*300
 $PieGraphDummies->zoomx(50); # new size : 150*300
 $PieGraphDummies->zoom(100); # new size : 300*300


Vertical zoom.

 # original canvas size 300*300
 $PieGraphDummies->zoomy(50); # new size : 300*150
 $PieGraphDummies->zoom(100); # new size : 300*300


See Tk::Canvas for details of the standard options.

See Tk::ForDummies::Graph, Tk::ForDummies::Graph::FAQ, GD::Graph.


Djibril Ousmanou, <djibel at>


Please report any bugs or feature requests to bug-tk-fordummies-graph at, or through the web interface at 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::ForDummies::Graph::Pie

You can also look for information at:


Copyright 2010 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.

syntax highlighting: