The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Chart::Gnuplot::Pie - Plot pie chart using Gnuplot on the fly

SYNOPSIS

use Chart::Gnuplot::Pie;

# Create the pie chart object
my $chart = Chart::Gnuplot::Pie->new(
    output => "pie.png",
    title  => "Sample Pie",
    ....
);

# Data set
my $dataSet = Chart::Gnuplot::Pie::DataSet->new(
    data => [
        ['Item 1', 7500],
        ['Item 2', 3500],
        ['Item 3', 2000],
        ['Item 4', 4500],
    ],
    ....
);

# Plot a 2D pie chart
$chart->plot2d($dataSet);

#################################################

# Plot a 3D pie chart
$chart->plot3d($dataSet);

DESCRIPTION

This module provides an interface for plotting pie charts using Gnuplot, which has not built-in command for pie. This module is an implementation of the idea of The Impossible Gnuplot Graphs. Gnuplot and Chart::Gnuplot are required.

IMPORTANT: This is a preliminary version. Not many pie charting options are provided currently. Besides, backward compatibility may not be guaranteed in the later versions.

PIE CHART OBJECT

Chart::Gnuplot::Pie is a child class of Chart::Gnuplot. As a result, what you may do on a Chart::Gnuplot object basically works on a Chart::Gnuplot::Pie object too, with a few exceptions.

Pie Chart Options

The following options have no effect since they have not much meaning in pie chart.

xlabel, ylabel, zlabel
x2label, y2label
xrange, yrange, zrange
x2range, y2range
trange, urange, vrange
xtics, ytics, ztics
x2tics, y2tics
timeaxis
grid

Besides, the following options, though can be meaningful, are not supported yet.

legend
size
bg
plotbg

Supported options are:

output
title
border
tmargin, bmargin
lmargin, rmargin
orient
imagesize
origin
timestamp
view (only 3D pie)
gnuplot
convert
terminal

DATASET OBJECT

Chart::Gnuplot::Pie::DataSet is a child class of Chart::Gnuplot::DataSet.

Dataset Options

The following options have no effect since they have not much meaning in pie dataset.

xdata, ydata, zdata
points
func
title
style
width
linetype
pointtype
pointsize
axes
smooth

Besides, the following options, though can be meaningful, are not supported yet.

datafile
fill
timefmt

Supported options are:

data
rotate
colors
border

data

The data that would be displayed in the pie chart. The data should be organized in a matrix of the format:

[
    ['Item 1', value 1],
    ['Item 2', value 2],
    ['Item 3', value 3],
    ['Item 4', value 4],
    .....
],

rotate

The angle (in degree) that the pie would be rotated anti-clockwisely. E.g.

rotate => -90    # rotate 90 degree clockwisely

colors

Color of each slice, in format of #RRGGBB. E.g. to set the second slice to "#99ccff",

colors => ["", "#99ccff", "", ....]

border

Border around and inside the pie. Currently, it is supported only for 2D pie. E.g.

border => {
    width => 3,
    color => "black",
}

Supported proerties are:

width
color

EXAMPLES

1. A simple 2D pie chart
my $c = Chart::Gnuplot::Pie->new(
    output   => "pie2d.png",
    title    => "Simple pie chart",
);

my $d = Chart::Gnuplot::Pie::DataSet->new(
    data => [
        ['Item 1', 7500],
        ['Item 2', 3500],
        ['Item 3', 2000],
        ['Item 4', 4500],
    ],
);

$c->plot2d($d);

2. A simple 3D pie chart
my $c = Chart::Gnuplot::Pie->new(
    output   => "pie3d.png",
    title    => "Simple pie chart",
);

my $d = Chart::Gnuplot::Pie::DataSet->new(
    data => [
        ['Item 1', 65],
        ['Item 2', 60],
        ['Item 3', 20],
        ['Item 4', 45],
        ['Item 5', 25],
    ],
);

$c->plot3d($d);

REQUIREMENT

Chart::Gnuplot

Gnuplot http://www.gnuplot.info

ImageMagick http://www.imagemagick.org (for full feature)

SEE ALSO

Chart::Gnuplot

Impossible Gnuplot Graphs: http://www.phyast.pitt.edu/~zov1/gnuplot/html/pie.html

AUTHOR

Ka-Wai Mak <kwmak@cpan.org>

COPYRIGHT

Copyright (c) 2009, 2011, 2013 Ka-Wai Mak. All rights reserved.

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.