#!perl use 5.012; # strict, // use warnings; use Excel::Writer::XLSX; ################ patch methods into ::Pie ################ package Excel::Writer::XLSX::Chart::Pie { sub add_series { my $self = shift; my %args = @_; $self->SUPER::add_series(@_); if(exists $args{explosion}) { $self->{_series}[-1]{_explosion} = $args{explosion}; # add explosion attribute to last-added series } } sub _write_explosion { my $self = shift; my $val = shift; if(defined $val) { my @attributes = ( 'val' => $val ); $self->xml_empty_tag( 'c:explosion', @attributes ); } } sub _write_ser { # copied from https://metacpan.org/dist/Excel-Writer-XLSX/source/lib/Excel/Writer/XLSX/Chart.pm; violates D.R.Y. # ideally, there should be a way to run the ...::Chart::_write_ser but just insert my one additional element from ::Chart::Pie::_write_ser(), but I don't know how to do that. my $self = shift; my $series = shift; my $index = $self->{_series_index}++; $self->xml_start_tag( 'c:ser' ); # Write the c:idx element. $self->_write_idx( $index ); # Write the c:order element. $self->_write_order( $index ); # Write the series name. $self->_write_series_name( $series ); # Write the c:spPr element. $self->_write_sp_pr( $series ); # Write the c:marker element. $self->_write_marker( $series->{_marker} ); # Write the c:invertIfNegative element. $self->_write_c_invert_if_negative( $series->{_invert_if_neg} ); # Write the c:dPt element. $self->_write_d_pt( $series->{_points} ); # Write the c:dLbls element. $self->_write_d_lbls( $series->{_labels} ); # Write the c:trendline element. $self->_write_trendline( $series->{_trendline} ); # Write the c:errBars element. $self->_write_error_bars( $series->{_error_bars} ); # Write the c:explosion element. # added by [pryrt] $self->_write_explosion( $series->{_explosion} ); # Write the c:cat element. $self->_write_cat( $series ); # Write the c:val element. $self->_write_val( $series ); # Write the c:smooth element. if ( $self->{_smooth_allowed} ) { $self->_write_c_smooth( $series->{_smooth} ); } $self->xml_end_tag( 'c:ser' ); } } ################ /end: patch methods into ::Pie ################ ################ back to the example from ::Pie SYNOPSIS, with added explosion attribute ################ my $workbook = Excel::Writer::XLSX->new('chart.xlsx'); my $worksheet = $workbook->add_worksheet(); my $chart = $workbook->add_chart( type => 'pie' ); # Configure the chart. $chart->add_series( categories => '=Sheet1!$A$2:$A$7', values => '=Sheet1!$B$2:$B$7', explosion => 5, ); # Add the worksheet data the chart refers to. my $data = [ [ 'Category', 2, 3, 4, 5, 6, 7 ], [ 'Value', 1, 4, 5, 2, 1, 5 ], ]; $worksheet->write( 'A1', $data ); __END__