{
    "mode": "perldoc",
    "parameter": "Spreadsheet::WriteExcel::Chart::Pie",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Spreadsheet%3A%3AWriteExcel%3A%3AChart%3A%3APie/json",
    "generated": "2026-06-10T20:27:18Z",
    "synopsis": "To create a simple Excel file with a Pie chart using Spreadsheet::WriteExcel:\n#!/usr/bin/perl -w\nuse strict;\nuse Spreadsheet::WriteExcel;\nmy $workbook  = Spreadsheet::WriteExcel->new( 'chart.xls' );\nmy $worksheet = $workbook->addworksheet();\nmy $chart     = $workbook->addchart( type => 'pie' );\n# Configure the chart.\n$chart->addseries(\ncategories => '=Sheet1!$A$2:$A$7',\nvalues     => '=Sheet1!$B$2:$B$7',\n);\n# Add the worksheet data the chart refers to.\nmy $data = [\n[ 'Category', 2, 3, 4, 5, 6, 7 ],\n[ 'Value',    1, 4, 5, 2, 1, 5 ],\n];\n$worksheet->write( 'A1', $data );\nEND",
    "sections": {
        "NAME": {
            "content": "Pie - A writer class for Excel Pie charts.\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "To create a simple Excel file with a Pie chart using Spreadsheet::WriteExcel:\n\n#!/usr/bin/perl -w\n\nuse strict;\nuse Spreadsheet::WriteExcel;\n\nmy $workbook  = Spreadsheet::WriteExcel->new( 'chart.xls' );\nmy $worksheet = $workbook->addworksheet();\n\nmy $chart     = $workbook->addchart( type => 'pie' );\n\n# Configure the chart.\n$chart->addseries(\ncategories => '=Sheet1!$A$2:$A$7',\nvalues     => '=Sheet1!$B$2:$B$7',\n);\n\n# Add the worksheet data the chart refers to.\nmy $data = [\n[ 'Category', 2, 3, 4, 5, 6, 7 ],\n[ 'Value',    1, 4, 5, 2, 1, 5 ],\n];\n\n$worksheet->write( 'A1', $data );\n\nEND\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module implements Pie charts for Spreadsheet::WriteExcel. The chart object is created via\nthe Workbook \"addchart()\" method:\n\nmy $chart = $workbook->addchart( type => 'pie' );\n\nOnce the object is created it can be configured via the following methods that are common to all\nchart classes:\n\n$chart->addseries();\n$chart->settitle();\n\nThese methods are explained in detail in Spreadsheet::WriteExcel::Chart. Class specific methods\nor settings, if any, are explained below.\n",
            "subsections": []
        },
        "Pie Chart Methods": {
            "content": "There aren't currently any pie chart specific methods. See the TODO section of\nSpreadsheet::WriteExcel::Chart.\n\nA Pie chart doesn't have an X or Y axis so the following common chart methods are ignored.\n\n$chart->setxaxis();\n$chart->setyaxis();\n",
            "subsections": []
        },
        "EXAMPLE": {
            "content": "Here is a complete example that demonstrates most of the available features when creating a\nchart.\n\n#!/usr/bin/perl -w\n\nuse strict;\nuse Spreadsheet::WriteExcel;\n\nmy $workbook  = Spreadsheet::WriteExcel->new( 'chartpie.xls' );\nmy $worksheet = $workbook->addworksheet();\nmy $bold      = $workbook->addformat( bold => 1 );\n\n# Add the worksheet data that the charts will refer to.\nmy $headings = [ 'Category', 'Values' ];\nmy $data = [\n[ 'Apple', 'Cherry', 'Pecan' ],\n[ 60,       30,       10     ],\n];\n\n$worksheet->write( 'A1', $headings, $bold );\n$worksheet->write( 'A2', $data );\n\n# Create a new chart object. In this case an embedded chart.\nmy $chart = $workbook->addchart( type => 'pie', embedded => 1 );\n\n# Configure the series.\n$chart->addseries(\nname       => 'Pie sales data',\ncategories => '=Sheet1!$A$2:$A$4',\nvalues     => '=Sheet1!$B$2:$B$4',\n);\n\n# Add a title.\n$chart->settitle( name => 'Popular Pie Types' );\n\n\n# Insert the chart into the worksheet (with an offset).\n$worksheet->insertchart( 'C2', $chart, 25, 10 );\n\nEND\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "John McNamara jmcnamara@cpan.org\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright MM-MMX, John McNamara.\n\nAll Rights Reserved. This module is free software. It may be used, redistributed and/or modified\nunder the same terms as Perl itself.\n",
            "subsections": []
        }
    },
    "summary": "Pie - A writer class for Excel Pie charts.",
    "flags": [],
    "examples": [
        "Here is a complete example that demonstrates most of the available features when creating a",
        "chart.",
        "#!/usr/bin/perl -w",
        "use strict;",
        "use Spreadsheet::WriteExcel;",
        "my $workbook  = Spreadsheet::WriteExcel->new( 'chartpie.xls' );",
        "my $worksheet = $workbook->addworksheet();",
        "my $bold      = $workbook->addformat( bold => 1 );",
        "# Add the worksheet data that the charts will refer to.",
        "my $headings = [ 'Category', 'Values' ];",
        "my $data = [",
        "[ 'Apple', 'Cherry', 'Pecan' ],",
        "[ 60,       30,       10     ],",
        "];",
        "$worksheet->write( 'A1', $headings, $bold );",
        "$worksheet->write( 'A2', $data );",
        "# Create a new chart object. In this case an embedded chart.",
        "my $chart = $workbook->addchart( type => 'pie', embedded => 1 );",
        "# Configure the series.",
        "$chart->addseries(",
        "name       => 'Pie sales data',",
        "categories => '=Sheet1!$A$2:$A$4',",
        "values     => '=Sheet1!$B$2:$B$4',",
        ");",
        "# Add a title.",
        "$chart->settitle( name => 'Popular Pie Types' );",
        "# Insert the chart into the worksheet (with an offset).",
        "$worksheet->insertchart( 'C2', $chart, 25, 10 );",
        "END"
    ],
    "see_also": []
}