This will produce a chart that looks like this:Īll Rights Reserved. # Insert the chart into the worksheet (with an offset). $chart->set_title( name => 'Popular Pie Types' ) Note the use of the array ref to define ranges: My $chart = $workbook->add_chart( type => 'pie', embedded => 1 ) $worksheet->write( 'A1', $headings, $bold ) # Add the worksheet data that the charts will refer to. My $bold = $workbook->add_format( bold => 1 ) You can combine a line chart or a bar chart to successfully make a data presentation. My $workbook = Excel::Writer::XLSX->new( 'chart_pie.xlsx' ) In this article, we compare different versions of Microsoft Excel. Here is a complete example that demonstrates most of the available features when creating a chart. Unsupported MethodsĪ Pie chart doesn't have an X or Y axis so the following common chart methods are ignored. Due to an Excel limitation (or design) leader lines only appear if the data label is moved manually or if the data labels are very close and need to be adjusted automatically. Note: Even when leader lines are turned on they aren't automatically visible in Excel or Excel::Writer::XLSX. Pie charts support leader lines: $chart->add_series( See the main Excel::Writer::XLSX::Chart documentation for more details. The angle of rotation must be 0 add_series( This has the effect of rotating the entire chart: $chart->set_rotation( 90 ) The set_rotation() method is used to set the rotation of the first segment of a Pie/Doughnut chart. Class specific methods or settings, if any, are explained below. These methods are explained in detail in Excel::Writer::XLSX::Chart. Once the object is created it can be configured via the following methods that are common to all chart classes: $chart->add_series() The chart object is created via the Workbook add_chart() method: my $chart = $workbook->add_chart( type => 'pie' ) This module implements Pie charts for Excel::Writer::XLSX. # Add the worksheet data the chart refers to. My $chart = $workbook->add_chart( type => 'pie' ) My $worksheet = $workbook->add_worksheet() My $workbook = Excel::Writer::XLSX->new( 'chart.xlsx' ) To create a simple Excel file with a Pie chart using Excel::Writer::XLSX: #!/usr/bin/perl Pie - A class for writing Excel Pie charts.