Initial Commit
This commit is contained in:
260
database/perl/vendor/lib/Excel/Writer/XLSX/Chart/Area.pm
vendored
Normal file
260
database/perl/vendor/lib/Excel/Writer/XLSX/Chart/Area.pm
vendored
Normal file
@@ -0,0 +1,260 @@
|
||||
package Excel::Writer::XLSX::Chart::Area;
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Area - A class for writing Excel Area charts.
|
||||
#
|
||||
# Used in conjunction with Excel::Writer::XLSX::Chart.
|
||||
#
|
||||
# See formatting note in Excel::Writer::XLSX::Chart.
|
||||
#
|
||||
# Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
|
||||
#
|
||||
# Documentation after __END__
|
||||
#
|
||||
|
||||
# perltidy with the following options: -mbl=2 -pt=0 -nola
|
||||
|
||||
use 5.008002;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Carp;
|
||||
use Excel::Writer::XLSX::Chart;
|
||||
|
||||
our @ISA = qw(Excel::Writer::XLSX::Chart);
|
||||
our $VERSION = '1.07';
|
||||
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# new()
|
||||
#
|
||||
#
|
||||
sub new {
|
||||
|
||||
my $class = shift;
|
||||
my $self = Excel::Writer::XLSX::Chart->new( @_ );
|
||||
|
||||
$self->{_subtype} = $self->{_subtype} || 'standard';
|
||||
$self->{_cross_between} = 'midCat';
|
||||
$self->{_show_crosses} = 0;
|
||||
|
||||
# Override and reset the default axis values.
|
||||
if ( $self->{_subtype} eq 'percent_stacked' ) {
|
||||
$self->{_y_axis}->{_defaults}->{num_format} = '0%';
|
||||
}
|
||||
|
||||
$self->set_y_axis();
|
||||
|
||||
# Sset the available data label positions for this chart type.
|
||||
$self->{_label_position_default} = 'center';
|
||||
$self->{_label_positions} = { center => 'ctr' };
|
||||
|
||||
bless $self, $class;
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_chart_type()
|
||||
#
|
||||
# Override the virtual superclass method with a chart specific method.
|
||||
#
|
||||
sub _write_chart_type {
|
||||
|
||||
my $self = shift;
|
||||
|
||||
# Write the c:areaChart element.
|
||||
$self->_write_area_chart( @_ );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_area_chart()
|
||||
#
|
||||
# Write the <c:areaChart> element.
|
||||
#
|
||||
sub _write_area_chart {
|
||||
|
||||
my $self = shift;
|
||||
my %args = @_;
|
||||
|
||||
my @series;
|
||||
if ( $args{primary_axes} ) {
|
||||
@series = $self->_get_primary_axes_series;
|
||||
}
|
||||
else {
|
||||
@series = $self->_get_secondary_axes_series;
|
||||
}
|
||||
|
||||
return unless scalar @series;
|
||||
|
||||
my $subtype = $self->{_subtype};
|
||||
|
||||
$subtype = 'percentStacked' if $subtype eq 'percent_stacked';
|
||||
|
||||
$self->xml_start_tag( 'c:areaChart' );
|
||||
|
||||
# Write the c:grouping element.
|
||||
$self->_write_grouping( $subtype );
|
||||
|
||||
# Write the series elements.
|
||||
$self->_write_series( $_ ) for @series;
|
||||
|
||||
# Write the c:dropLines element.
|
||||
$self->_write_drop_lines();
|
||||
|
||||
# Write the c:axId elements
|
||||
$self->_write_axis_ids( %args );
|
||||
|
||||
$self->xml_end_tag( 'c:areaChart' );
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
||||
__END__
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Area - A class for writing Excel Area charts.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
To create a simple Excel file with an Area chart using Excel::Writer::XLSX:
|
||||
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Excel::Writer::XLSX;
|
||||
|
||||
my $workbook = Excel::Writer::XLSX->new( 'chart.xlsx' );
|
||||
my $worksheet = $workbook->add_worksheet();
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'area' );
|
||||
|
||||
# Configure the chart.
|
||||
$chart->add_series(
|
||||
categories => '=Sheet1!$A$2:$A$7',
|
||||
values => '=Sheet1!$B$2:$B$7',
|
||||
);
|
||||
|
||||
# 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__
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements Area charts for L<Excel::Writer::XLSX>. The chart object is created via the Workbook C<add_chart()> method:
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'area' );
|
||||
|
||||
Once the object is created it can be configured via the following methods that are common to all chart classes:
|
||||
|
||||
$chart->add_series();
|
||||
$chart->set_x_axis();
|
||||
$chart->set_y_axis();
|
||||
$chart->set_title();
|
||||
|
||||
These methods are explained in detail in L<Excel::Writer::XLSX::Chart>. Class specific methods or settings, if any, are explained below.
|
||||
|
||||
=head1 Area Chart Subtypes
|
||||
|
||||
|
||||
The C<Area> chart module also supports the following sub-types:
|
||||
|
||||
stacked
|
||||
percent_stacked
|
||||
|
||||
These can be specified at creation time via the C<add_chart()> Worksheet method:
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'area', subtype => 'stacked' );
|
||||
|
||||
=head1 EXAMPLE
|
||||
|
||||
Here is a complete example that demonstrates most of the available features when creating a chart.
|
||||
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Excel::Writer::XLSX;
|
||||
|
||||
my $workbook = Excel::Writer::XLSX->new( 'chart_area.xlsx' );
|
||||
my $worksheet = $workbook->add_worksheet();
|
||||
my $bold = $workbook->add_format( bold => 1 );
|
||||
|
||||
# Add the worksheet data that the charts will refer to.
|
||||
my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
|
||||
my $data = [
|
||||
[ 2, 3, 4, 5, 6, 7 ],
|
||||
[ 40, 40, 50, 30, 25, 50 ],
|
||||
[ 30, 25, 30, 10, 5, 10 ],
|
||||
|
||||
];
|
||||
|
||||
$worksheet->write( 'A1', $headings, $bold );
|
||||
$worksheet->write( 'A2', $data );
|
||||
|
||||
# Create a new chart object. In this case an embedded chart.
|
||||
my $chart = $workbook->add_chart( type => 'area', embedded => 1 );
|
||||
|
||||
# Configure the first series.
|
||||
$chart->add_series(
|
||||
name => '=Sheet1!$B$1',
|
||||
categories => '=Sheet1!$A$2:$A$7',
|
||||
values => '=Sheet1!$B$2:$B$7',
|
||||
);
|
||||
|
||||
# Configure second series. Note alternative use of array ref to define
|
||||
# ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
|
||||
$chart->add_series(
|
||||
name => '=Sheet1!$C$1',
|
||||
categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
||||
values => [ 'Sheet1', 1, 6, 2, 2 ],
|
||||
);
|
||||
|
||||
# Add a chart title and some axis labels.
|
||||
$chart->set_title ( name => 'Results of sample analysis' );
|
||||
$chart->set_x_axis( name => 'Test number' );
|
||||
$chart->set_y_axis( name => 'Sample length (mm)' );
|
||||
|
||||
# Set an Excel chart style. Blue colors with white outline and shadow.
|
||||
$chart->set_style( 11 );
|
||||
|
||||
# Insert the chart into the worksheet (with an offset).
|
||||
$worksheet->insert_chart( 'D2', $chart, 25, 10 );
|
||||
|
||||
__END__
|
||||
|
||||
|
||||
=begin html
|
||||
|
||||
<p>This will produce a chart that looks like this:</p>
|
||||
|
||||
<p><center><img src="http://jmcnamara.github.io/excel-writer-xlsx/images/examples/area1.jpg" width="483" height="291" alt="Chart example." /></center></p>
|
||||
|
||||
=end html
|
||||
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
John McNamara jmcnamara@cpan.org
|
||||
|
||||
=head1 COPYRIGHT
|
||||
|
||||
Copyright MM-MMXX, John McNamara.
|
||||
|
||||
All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
|
||||
|
||||
352
database/perl/vendor/lib/Excel/Writer/XLSX/Chart/Bar.pm
vendored
Normal file
352
database/perl/vendor/lib/Excel/Writer/XLSX/Chart/Bar.pm
vendored
Normal file
@@ -0,0 +1,352 @@
|
||||
package Excel::Writer::XLSX::Chart::Bar;
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Bar - A class for writing Excel Bar charts.
|
||||
#
|
||||
# Used in conjunction with Excel::Writer::XLSX::Chart.
|
||||
#
|
||||
# See formatting note in Excel::Writer::XLSX::Chart.
|
||||
#
|
||||
# Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
|
||||
#
|
||||
# Documentation after __END__
|
||||
#
|
||||
|
||||
# perltidy with the following options: -mbl=2 -pt=0 -nola
|
||||
|
||||
use 5.008002;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Carp;
|
||||
use Excel::Writer::XLSX::Chart;
|
||||
|
||||
our @ISA = qw(Excel::Writer::XLSX::Chart);
|
||||
our $VERSION = '1.07';
|
||||
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# new()
|
||||
#
|
||||
#
|
||||
sub new {
|
||||
|
||||
my $class = shift;
|
||||
my $self = Excel::Writer::XLSX::Chart->new( @_ );
|
||||
|
||||
$self->{_subtype} = $self->{_subtype} || 'clustered';
|
||||
$self->{_cat_axis_position} = 'l';
|
||||
$self->{_val_axis_position} = 'b';
|
||||
$self->{_horiz_val_axis} = 0;
|
||||
$self->{_horiz_cat_axis} = 1;
|
||||
$self->{_show_crosses} = 0;
|
||||
|
||||
# Override and reset the default axis values.
|
||||
$self->{_x_axis}->{_defaults}->{major_gridlines} = { visible => 1 };
|
||||
$self->{_y_axis}->{_defaults}->{major_gridlines} = { visible => 0 };
|
||||
|
||||
if ( $self->{_subtype} eq 'percent_stacked' ) {
|
||||
$self->{_x_axis}->{_defaults}->{num_format} = '0%';
|
||||
}
|
||||
|
||||
$self->set_x_axis();
|
||||
$self->set_y_axis();
|
||||
|
||||
# Set the available data label positions for this chart type.
|
||||
$self->{_label_position_default} = 'outside_end';
|
||||
$self->{_label_positions} = {
|
||||
center => 'ctr',
|
||||
inside_base => 'inBase',
|
||||
inside_end => 'inEnd',
|
||||
outside_end => 'outEnd',
|
||||
};
|
||||
|
||||
bless $self, $class;
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# combine()
|
||||
#
|
||||
# Override parent method to add an extra check that is required for Bar
|
||||
# charts to ensure that their combined chart is on a secondary axis.
|
||||
#
|
||||
sub combine {
|
||||
|
||||
my $self = shift;
|
||||
my $chart = shift;
|
||||
|
||||
if (!$chart->{_is_secondary}) {
|
||||
carp 'Charts combined with Bar charts must be on a secondary axis';
|
||||
return;
|
||||
}
|
||||
|
||||
$self->{_combined} = $chart;
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_chart_type()
|
||||
#
|
||||
# Override the virtual superclass method with a chart specific method.
|
||||
#
|
||||
sub _write_chart_type {
|
||||
|
||||
my $self = shift;
|
||||
my %args = @_;
|
||||
|
||||
if ( $args{primary_axes} ) {
|
||||
|
||||
# Reverse X and Y axes for Bar charts.
|
||||
my $tmp = $self->{_y_axis};
|
||||
$self->{_y_axis} = $self->{_x_axis};
|
||||
$self->{_x_axis} = $tmp;
|
||||
|
||||
if ( $self->{_y2_axis}->{_position} eq 'r' ) {
|
||||
$self->{_y2_axis}->{_position} = 't';
|
||||
}
|
||||
}
|
||||
|
||||
# Write the c:barChart element.
|
||||
$self->_write_bar_chart( @_ );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_bar_chart()
|
||||
#
|
||||
# Write the <c:barChart> element.
|
||||
#
|
||||
sub _write_bar_chart {
|
||||
|
||||
my $self = shift;
|
||||
my %args = @_;
|
||||
|
||||
my @series;
|
||||
if ( $args{primary_axes} ) {
|
||||
@series = $self->_get_primary_axes_series;
|
||||
}
|
||||
else {
|
||||
@series = $self->_get_secondary_axes_series;
|
||||
}
|
||||
|
||||
return unless scalar @series;
|
||||
|
||||
my $subtype = $self->{_subtype};
|
||||
$subtype = 'percentStacked' if $subtype eq 'percent_stacked';
|
||||
|
||||
# Set a default overlap for stacked charts.
|
||||
if ($self->{_subtype} =~ /stacked/) {
|
||||
if (!defined $self->{_series_overlap_1}) {
|
||||
$self->{_series_overlap_1} = 100;
|
||||
}
|
||||
}
|
||||
|
||||
$self->xml_start_tag( 'c:barChart' );
|
||||
|
||||
# Write the c:barDir element.
|
||||
$self->_write_bar_dir();
|
||||
|
||||
# Write the c:grouping element.
|
||||
$self->_write_grouping( $subtype );
|
||||
|
||||
# Write the c:ser elements.
|
||||
$self->_write_ser( $_ ) for @series;
|
||||
|
||||
if ( $args{primary_axes} ) {
|
||||
# Write the c:gapWidth element.
|
||||
$self->_write_gap_width( $self->{_series_gap_1} );
|
||||
|
||||
# Write the c:overlap element.
|
||||
$self->_write_overlap( $self->{_series_overlap_1} );
|
||||
}
|
||||
else {
|
||||
# Write the c:gapWidth element.
|
||||
$self->_write_gap_width( $self->{_series_gap_2} );
|
||||
|
||||
# Write the c:overlap element.
|
||||
$self->_write_overlap( $self->{_series_overlap_2} );
|
||||
}
|
||||
|
||||
# Write the c:axId elements
|
||||
$self->_write_axis_ids( %args );
|
||||
|
||||
$self->xml_end_tag( 'c:barChart' );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_bar_dir()
|
||||
#
|
||||
# Write the <c:barDir> element.
|
||||
#
|
||||
sub _write_bar_dir {
|
||||
|
||||
my $self = shift;
|
||||
my $val = 'bar';
|
||||
|
||||
my @attributes = ( 'val' => $val );
|
||||
|
||||
$self->xml_empty_tag( 'c:barDir', @attributes );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_err_dir()
|
||||
#
|
||||
# Write the <c:errDir> element. Overridden from Chart class since it is not
|
||||
# used in Bar charts.
|
||||
#
|
||||
sub _write_err_dir {}
|
||||
|
||||
1;
|
||||
|
||||
|
||||
__END__
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Bar - A class for writing Excel Bar charts.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
To create a simple Excel file with a Bar chart using Excel::Writer::XLSX:
|
||||
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Excel::Writer::XLSX;
|
||||
|
||||
my $workbook = Excel::Writer::XLSX->new( 'chart.xlsx' );
|
||||
my $worksheet = $workbook->add_worksheet();
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'bar' );
|
||||
|
||||
# Configure the chart.
|
||||
$chart->add_series(
|
||||
categories => '=Sheet1!$A$2:$A$7',
|
||||
values => '=Sheet1!$B$2:$B$7',
|
||||
);
|
||||
|
||||
# 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__
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements Bar charts for L<Excel::Writer::XLSX>. The chart object is created via the Workbook C<add_chart()> method:
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'bar' );
|
||||
|
||||
Once the object is created it can be configured via the following methods that are common to all chart classes:
|
||||
|
||||
$chart->add_series();
|
||||
$chart->set_x_axis();
|
||||
$chart->set_y_axis();
|
||||
$chart->set_title();
|
||||
|
||||
These methods are explained in detail in L<Excel::Writer::XLSX::Chart>. Class specific methods or settings, if any, are explained below.
|
||||
|
||||
=head1 Bar Chart Subtypes
|
||||
|
||||
The C<Bar> chart module also supports the following sub-types:
|
||||
|
||||
stacked
|
||||
percent_stacked
|
||||
|
||||
These can be specified at creation time via the C<add_chart()> Worksheet method:
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'bar', subtype => 'stacked' );
|
||||
|
||||
=head1 EXAMPLE
|
||||
|
||||
Here is a complete example that demonstrates most of the available features when creating a chart.
|
||||
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Excel::Writer::XLSX;
|
||||
|
||||
my $workbook = Excel::Writer::XLSX->new( 'chart_bar.xlsx' );
|
||||
my $worksheet = $workbook->add_worksheet();
|
||||
my $bold = $workbook->add_format( bold => 1 );
|
||||
|
||||
# Add the worksheet data that the charts will refer to.
|
||||
my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
|
||||
my $data = [
|
||||
[ 2, 3, 4, 5, 6, 7 ],
|
||||
[ 10, 40, 50, 20, 10, 50 ],
|
||||
[ 30, 60, 70, 50, 40, 30 ],
|
||||
|
||||
];
|
||||
|
||||
$worksheet->write( 'A1', $headings, $bold );
|
||||
$worksheet->write( 'A2', $data );
|
||||
|
||||
# Create a new chart object. In this case an embedded chart.
|
||||
my $chart = $workbook->add_chart( type => 'bar', embedded => 1 );
|
||||
|
||||
# Configure the first series.
|
||||
$chart->add_series(
|
||||
name => '=Sheet1!$B$1',
|
||||
categories => '=Sheet1!$A$2:$A$7',
|
||||
values => '=Sheet1!$B$2:$B$7',
|
||||
);
|
||||
|
||||
# Configure second series. Note alternative use of array ref to define
|
||||
# ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
|
||||
$chart->add_series(
|
||||
name => '=Sheet1!$C$1',
|
||||
categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
||||
values => [ 'Sheet1', 1, 6, 2, 2 ],
|
||||
);
|
||||
|
||||
# Add a chart title and some axis labels.
|
||||
$chart->set_title ( name => 'Results of sample analysis' );
|
||||
$chart->set_x_axis( name => 'Test number' );
|
||||
$chart->set_y_axis( name => 'Sample length (mm)' );
|
||||
|
||||
# Set an Excel chart style. Blue colors with white outline and shadow.
|
||||
$chart->set_style( 11 );
|
||||
|
||||
# Insert the chart into the worksheet (with an offset).
|
||||
$worksheet->insert_chart( 'D2', $chart, 25, 10 );
|
||||
|
||||
__END__
|
||||
|
||||
|
||||
=begin html
|
||||
|
||||
<p>This will produce a chart that looks like this:</p>
|
||||
|
||||
<p><center><img src="http://jmcnamara.github.io/excel-writer-xlsx/images/examples/bar1.jpg" width="483" height="291" alt="Chart example." /></center></p>
|
||||
|
||||
=end html
|
||||
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
John McNamara jmcnamara@cpan.org
|
||||
|
||||
=head1 COPYRIGHT
|
||||
|
||||
Copyright MM-MMXX, John McNamara.
|
||||
|
||||
All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
|
||||
|
||||
312
database/perl/vendor/lib/Excel/Writer/XLSX/Chart/Column.pm
vendored
Normal file
312
database/perl/vendor/lib/Excel/Writer/XLSX/Chart/Column.pm
vendored
Normal file
@@ -0,0 +1,312 @@
|
||||
package Excel::Writer::XLSX::Chart::Column;
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Column - A class for writing Excel Column charts.
|
||||
#
|
||||
# Used in conjunction with Excel::Writer::XLSX::Chart.
|
||||
#
|
||||
# See formatting note in Excel::Writer::XLSX::Chart.
|
||||
#
|
||||
# Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
|
||||
#
|
||||
# Documentation after __END__
|
||||
#
|
||||
|
||||
# perltidy with the following options: -mbl=2 -pt=0 -nola
|
||||
|
||||
use 5.008002;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Carp;
|
||||
use Excel::Writer::XLSX::Chart;
|
||||
|
||||
our @ISA = qw(Excel::Writer::XLSX::Chart);
|
||||
our $VERSION = '1.07';
|
||||
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# new()
|
||||
#
|
||||
#
|
||||
sub new {
|
||||
|
||||
my $class = shift;
|
||||
my $self = Excel::Writer::XLSX::Chart->new( @_ );
|
||||
|
||||
$self->{_subtype} = $self->{_subtype} || 'clustered';
|
||||
$self->{_horiz_val_axis} = 0;
|
||||
|
||||
# Override and reset the default axis values.
|
||||
if ( $self->{_subtype} eq 'percent_stacked' ) {
|
||||
$self->{_y_axis}->{_defaults}->{num_format} = '0%';
|
||||
}
|
||||
|
||||
$self->set_y_axis();
|
||||
|
||||
# Set the available data label positions for this chart type.
|
||||
$self->{_label_position_default} = 'outside_end';
|
||||
$self->{_label_positions} = {
|
||||
center => 'ctr',
|
||||
inside_base => 'inBase',
|
||||
inside_end => 'inEnd',
|
||||
outside_end => 'outEnd',
|
||||
};
|
||||
|
||||
bless $self, $class;
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_chart_type()
|
||||
#
|
||||
# Override the virtual superclass method with a chart specific method.
|
||||
#
|
||||
sub _write_chart_type {
|
||||
|
||||
my $self = shift;
|
||||
|
||||
# Write the c:barChart element.
|
||||
$self->_write_bar_chart( @_ );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_bar_chart()
|
||||
#
|
||||
# Write the <c:barChart> element.
|
||||
#
|
||||
sub _write_bar_chart {
|
||||
|
||||
my $self = shift;
|
||||
my %args = @_;
|
||||
|
||||
my @series;
|
||||
if ( $args{primary_axes} ) {
|
||||
@series = $self->_get_primary_axes_series;
|
||||
}
|
||||
else {
|
||||
@series = $self->_get_secondary_axes_series;
|
||||
}
|
||||
|
||||
return unless scalar @series;
|
||||
|
||||
my $subtype = $self->{_subtype};
|
||||
$subtype = 'percentStacked' if $subtype eq 'percent_stacked';
|
||||
|
||||
# Set a default overlap for stacked charts.
|
||||
if ($self->{_subtype} =~ /stacked/) {
|
||||
if (!defined $self->{_series_overlap_1}) {
|
||||
$self->{_series_overlap_1} = 100;
|
||||
}
|
||||
}
|
||||
|
||||
$self->xml_start_tag( 'c:barChart' );
|
||||
|
||||
# Write the c:barDir element.
|
||||
$self->_write_bar_dir();
|
||||
|
||||
# Write the c:grouping element.
|
||||
$self->_write_grouping( $subtype );
|
||||
|
||||
# Write the c:ser elements.
|
||||
$self->_write_ser( $_ ) for @series;
|
||||
|
||||
if ( $args{primary_axes} ) {
|
||||
# Write the c:gapWidth element.
|
||||
$self->_write_gap_width( $self->{_series_gap_1} );
|
||||
|
||||
# Write the c:overlap element.
|
||||
$self->_write_overlap( $self->{_series_overlap_1} );
|
||||
}
|
||||
else {
|
||||
# Write the c:gapWidth element.
|
||||
$self->_write_gap_width( $self->{_series_gap_2} );
|
||||
|
||||
# Write the c:overlap element.
|
||||
$self->_write_overlap( $self->{_series_overlap_2} );
|
||||
}
|
||||
|
||||
# Write the c:axId elements
|
||||
$self->_write_axis_ids( %args );
|
||||
|
||||
$self->xml_end_tag( 'c:barChart' );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_bar_dir()
|
||||
#
|
||||
# Write the <c:barDir> element.
|
||||
#
|
||||
sub _write_bar_dir {
|
||||
|
||||
my $self = shift;
|
||||
my $val = 'col';
|
||||
|
||||
my @attributes = ( 'val' => $val );
|
||||
|
||||
$self->xml_empty_tag( 'c:barDir', @attributes );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_err_dir()
|
||||
#
|
||||
# Write the <c:errDir> element. Overridden from Chart class since it is not
|
||||
# used in Bar charts.
|
||||
#
|
||||
sub _write_err_dir {}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
||||
__END__
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Column - A class for writing Excel Column charts.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
To create a simple Excel file with a Column chart using Excel::Writer::XLSX:
|
||||
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Excel::Writer::XLSX;
|
||||
|
||||
my $workbook = Excel::Writer::XLSX->new( 'chart.xlsx' );
|
||||
my $worksheet = $workbook->add_worksheet();
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'column' );
|
||||
|
||||
# Configure the chart.
|
||||
$chart->add_series(
|
||||
categories => '=Sheet1!$A$2:$A$7',
|
||||
values => '=Sheet1!$B$2:$B$7',
|
||||
);
|
||||
|
||||
# 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__
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements Column charts for L<Excel::Writer::XLSX>. The chart object is created via the Workbook C<add_chart()> method:
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'column' );
|
||||
|
||||
Once the object is created it can be configured via the following methods that are common to all chart classes:
|
||||
|
||||
$chart->add_series();
|
||||
$chart->set_x_axis();
|
||||
$chart->set_y_axis();
|
||||
$chart->set_title();
|
||||
|
||||
These methods are explained in detail in L<Excel::Writer::XLSX::Chart>. Class specific methods or settings, if any, are explained below.
|
||||
|
||||
=head1 Column Chart Subtypes
|
||||
|
||||
The C<Column> chart module also supports the following sub-types:
|
||||
|
||||
stacked
|
||||
percent_stacked
|
||||
|
||||
These can be specified at creation time via the C<add_chart()> Worksheet method:
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'column', subtype => 'stacked' );
|
||||
|
||||
=head1 EXAMPLE
|
||||
|
||||
Here is a complete example that demonstrates most of the available features when creating a chart.
|
||||
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Excel::Writer::XLSX;
|
||||
|
||||
my $workbook = Excel::Writer::XLSX->new( 'chart_column.xlsx' );
|
||||
my $worksheet = $workbook->add_worksheet();
|
||||
my $bold = $workbook->add_format( bold => 1 );
|
||||
|
||||
# Add the worksheet data that the charts will refer to.
|
||||
my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
|
||||
my $data = [
|
||||
[ 2, 3, 4, 5, 6, 7 ],
|
||||
[ 10, 40, 50, 20, 10, 50 ],
|
||||
[ 30, 60, 70, 50, 40, 30 ],
|
||||
|
||||
];
|
||||
|
||||
$worksheet->write( 'A1', $headings, $bold );
|
||||
$worksheet->write( 'A2', $data );
|
||||
|
||||
# Create a new chart object. In this case an embedded chart.
|
||||
my $chart = $workbook->add_chart( type => 'column', embedded => 1 );
|
||||
|
||||
# Configure the first series.
|
||||
$chart->add_series(
|
||||
name => '=Sheet1!$B$1',
|
||||
categories => '=Sheet1!$A$2:$A$7',
|
||||
values => '=Sheet1!$B$2:$B$7',
|
||||
);
|
||||
|
||||
# Configure second series. Note alternative use of array ref to define
|
||||
# ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
|
||||
$chart->add_series(
|
||||
name => '=Sheet1!$C$1',
|
||||
categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
||||
values => [ 'Sheet1', 1, 6, 2, 2 ],
|
||||
);
|
||||
|
||||
# Add a chart title and some axis labels.
|
||||
$chart->set_title ( name => 'Results of sample analysis' );
|
||||
$chart->set_x_axis( name => 'Test number' );
|
||||
$chart->set_y_axis( name => 'Sample length (mm)' );
|
||||
|
||||
# Set an Excel chart style. Blue colors with white outline and shadow.
|
||||
$chart->set_style( 11 );
|
||||
|
||||
# Insert the chart into the worksheet (with an offset).
|
||||
$worksheet->insert_chart( 'D2', $chart, 25, 10 );
|
||||
|
||||
__END__
|
||||
|
||||
|
||||
=begin html
|
||||
|
||||
<p>This will produce a chart that looks like this:</p>
|
||||
|
||||
<p><center><img src="http://jmcnamara.github.io/excel-writer-xlsx/images/examples/column1.jpg" width="483" height="291" alt="Chart example." /></center></p>
|
||||
|
||||
=end html
|
||||
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
John McNamara jmcnamara@cpan.org
|
||||
|
||||
=head1 COPYRIGHT
|
||||
|
||||
Copyright MM-MMXX, John McNamara.
|
||||
|
||||
All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
|
||||
|
||||
305
database/perl/vendor/lib/Excel/Writer/XLSX/Chart/Doughnut.pm
vendored
Normal file
305
database/perl/vendor/lib/Excel/Writer/XLSX/Chart/Doughnut.pm
vendored
Normal file
@@ -0,0 +1,305 @@
|
||||
package Excel::Writer::XLSX::Chart::Doughnut;
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Doughnut - A class for writing Excel Doughnut charts.
|
||||
#
|
||||
# Used in conjunction with Excel::Writer::XLSX::Chart.
|
||||
#
|
||||
# See formatting note in Excel::Writer::XLSX::Chart.
|
||||
#
|
||||
# Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
|
||||
#
|
||||
# Documentation after __END__
|
||||
#
|
||||
|
||||
# perltidy with the following options: -mbl=2 -pt=0 -nola
|
||||
|
||||
use 5.008002;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Carp;
|
||||
use Excel::Writer::XLSX::Chart::Pie;
|
||||
|
||||
our @ISA = qw(Excel::Writer::XLSX::Chart::Pie);
|
||||
our $VERSION = '1.07';
|
||||
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# new()
|
||||
#
|
||||
#
|
||||
sub new {
|
||||
|
||||
my $class = shift;
|
||||
my $self = Excel::Writer::XLSX::Chart::Pie->new( @_ );
|
||||
|
||||
$self->{_vary_data_color} = 1;
|
||||
$self->{_hole_size} = 50;
|
||||
$self->{_rotation} = 0;
|
||||
|
||||
bless $self, $class;
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# set_hole_size()
|
||||
#
|
||||
# Set the Doughnut chart hole size.
|
||||
#
|
||||
sub set_hole_size {
|
||||
|
||||
my $self = shift;
|
||||
my $size = shift;
|
||||
|
||||
return if !defined $size;
|
||||
|
||||
if ( $size >= 10 && $size <= 90 ) {
|
||||
$self->{_hole_size} = $size;
|
||||
}
|
||||
else {
|
||||
carp "Hole size $size outside Excel range: 10 <= size <= 90";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_chart_type()
|
||||
#
|
||||
# Override the virtual superclass method with a chart specific method.
|
||||
#
|
||||
sub _write_chart_type {
|
||||
|
||||
my $self = shift;
|
||||
|
||||
# Write the c:doughnutChart element.
|
||||
$self->_write_doughnut_chart( @_ );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_doughnut_chart()
|
||||
#
|
||||
# Write the <c:doughnutChart> element. Over-ridden method to remove axis_id code
|
||||
# since Doughnut charts don't require val and cat axes.
|
||||
#
|
||||
sub _write_doughnut_chart {
|
||||
|
||||
my $self = shift;
|
||||
|
||||
$self->xml_start_tag( 'c:doughnutChart' );
|
||||
|
||||
# Write the c:varyColors element.
|
||||
$self->_write_vary_colors();
|
||||
|
||||
# Write the series elements.
|
||||
$self->_write_ser( $_ ) for @{ $self->{_series} };
|
||||
|
||||
# Write the c:firstSliceAng element.
|
||||
$self->_write_first_slice_ang();
|
||||
|
||||
# Write the c:holeSize element.
|
||||
$self->_write_hole_size();
|
||||
|
||||
$self->xml_end_tag( 'c:doughnutChart' );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_hole_size()
|
||||
#
|
||||
# Write the <c:holeSize> element.
|
||||
#
|
||||
sub _write_hole_size {
|
||||
|
||||
my $self = shift;
|
||||
my $val = $self->{_hole_size};
|
||||
|
||||
my @attributes = ( 'val' => $val );
|
||||
|
||||
$self->xml_empty_tag( 'c:holeSize', @attributes );
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
||||
__END__
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Doughnut - A class for writing Excel Doughnut charts.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
To create a simple Excel file with a Doughnut chart using Excel::Writer::XLSX:
|
||||
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Excel::Writer::XLSX;
|
||||
|
||||
my $workbook = Excel::Writer::XLSX->new( 'chart.xlsx' );
|
||||
my $worksheet = $workbook->add_worksheet();
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'doughnut' );
|
||||
|
||||
# Configure the chart.
|
||||
$chart->add_series(
|
||||
categories => '=Sheet1!$A$2:$A$7',
|
||||
values => '=Sheet1!$B$2:$B$7',
|
||||
);
|
||||
|
||||
# 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__
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements Doughnut charts for L<Excel::Writer::XLSX>. The chart object is created via the Workbook C<add_chart()> method:
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'doughnut' );
|
||||
|
||||
Once the object is created it can be configured via the following methods that are common to all chart classes:
|
||||
|
||||
$chart->add_series();
|
||||
$chart->set_title();
|
||||
|
||||
These methods are explained in detail in L<Excel::Writer::XLSX::Chart>. Class specific methods or settings, if any, are explained below.
|
||||
|
||||
=head1 Doughnut Chart Methods
|
||||
|
||||
=head2 set_rotation()
|
||||
|
||||
The C<set_rotation()> method is used to set the rotation of the first segment of a Pie/Doughnut chart. This has the effect of rotating the entire chart:
|
||||
|
||||
$chart->set_rotation( 90 );
|
||||
|
||||
The angle of rotation must be C<< 0 <= rotation <= 360 >>.
|
||||
|
||||
|
||||
=head2 set_hole_size()
|
||||
|
||||
The C<set_hole_size()> method is used to set the hole size of a Doughnut chart:
|
||||
|
||||
$chart->set_hole_size( 33 );
|
||||
|
||||
The the hole size must be a percentage in the range C<< 10 <= size <= 90 >>.
|
||||
|
||||
|
||||
=head2 User defined colors
|
||||
|
||||
It is possible to define chart colors for most types of Excel::Writer::XLSX charts via the add_series() method. However, Pie/Doughnut charts are a special case since each segment is represented as a point so it is necessary to assign formatting to each point in the series:
|
||||
|
||||
$chart->add_series(
|
||||
values => '=Sheet1!$A$1:$A$3',
|
||||
points => [
|
||||
{ fill => { color => '#FF0000' } },
|
||||
{ fill => { color => '#CC0000' } },
|
||||
{ fill => { color => '#990000' } },
|
||||
],
|
||||
);
|
||||
|
||||
See the main L<Excel::Writer::XLSX::Chart> documentation for more details.
|
||||
|
||||
Doughnut charts support leader lines:
|
||||
|
||||
$chart->add_series(
|
||||
name => 'Doughnut sales data',
|
||||
categories => [ 'Sheet1', 1, 3, 0, 0 ],
|
||||
values => [ 'Sheet1', 1, 3, 1, 1 ],
|
||||
data_labels => {
|
||||
series_name => 1,
|
||||
percentage => 1,
|
||||
leader_lines => 1,
|
||||
position => 'outside_end'
|
||||
},
|
||||
);
|
||||
|
||||
Note: Even when leader lines are turned on they aren't automatically visible in Excel or Excel::Writer::XLSX. 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.
|
||||
|
||||
=head2 Unsupported Methods
|
||||
|
||||
A Doughnut chart doesn't have an X or Y axis so the following common chart methods are ignored.
|
||||
|
||||
$chart->set_x_axis();
|
||||
$chart->set_y_axis();
|
||||
|
||||
=head1 EXAMPLE
|
||||
|
||||
Here is a complete example that demonstrates most of the available features when creating a chart.
|
||||
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Excel::Writer::XLSX;
|
||||
|
||||
my $workbook = Excel::Writer::XLSX->new( 'chart_doughnut.xlsx' );
|
||||
my $worksheet = $workbook->add_worksheet();
|
||||
my $bold = $workbook->add_format( bold => 1 );
|
||||
|
||||
# Add the worksheet data that the charts will refer to.
|
||||
my $headings = [ 'Category', 'Values' ];
|
||||
my $data = [
|
||||
[ 'Glazed', 'Chocolate', 'Cream' ],
|
||||
[ 50, 35, 15 ],
|
||||
];
|
||||
|
||||
$worksheet->write( 'A1', $headings, $bold );
|
||||
$worksheet->write( 'A2', $data );
|
||||
|
||||
# Create a new chart object. In this case an embedded chart.
|
||||
my $chart = $workbook->add_chart( type => 'doughnut', embedded => 1 );
|
||||
|
||||
# Configure the series. Note the use of the array ref to define ranges:
|
||||
# [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
|
||||
$chart->add_series(
|
||||
name => 'Doughnut sales data',
|
||||
categories => [ 'Sheet1', 1, 3, 0, 0 ],
|
||||
values => [ 'Sheet1', 1, 3, 1, 1 ],
|
||||
);
|
||||
|
||||
# Add a title.
|
||||
$chart->set_title( name => 'Popular Doughnut Types' );
|
||||
|
||||
# Set an Excel chart style. Colors with white outline and shadow.
|
||||
$chart->set_style( 10 );
|
||||
|
||||
# Insert the chart into the worksheet (with an offset).
|
||||
$worksheet->insert_chart( 'C2', $chart, 25, 10 );
|
||||
|
||||
__END__
|
||||
|
||||
|
||||
=begin html
|
||||
|
||||
<p>This will produce a chart that looks like this:</p>
|
||||
|
||||
<p><center><img src="http://jmcnamara.github.io/excel-writer-xlsx/images/examples/doughnut1.jpg" width="483" height="291" alt="Chart example." /></center></p>
|
||||
|
||||
=end html
|
||||
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
John McNamara jmcnamara@cpan.org
|
||||
|
||||
=head1 COPYRIGHT
|
||||
|
||||
Copyright MM-MMXX, John McNamara.
|
||||
|
||||
All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
|
||||
321
database/perl/vendor/lib/Excel/Writer/XLSX/Chart/Line.pm
vendored
Normal file
321
database/perl/vendor/lib/Excel/Writer/XLSX/Chart/Line.pm
vendored
Normal file
@@ -0,0 +1,321 @@
|
||||
package Excel::Writer::XLSX::Chart::Line;
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Line - A class for writing Excel Line charts.
|
||||
#
|
||||
# Used in conjunction with Excel::Writer::XLSX::Chart.
|
||||
#
|
||||
# See formatting note in Excel::Writer::XLSX::Chart.
|
||||
#
|
||||
# Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
|
||||
#
|
||||
# Documentation after __END__
|
||||
#
|
||||
|
||||
# perltidy with the following options: -mbl=2 -pt=0 -nola
|
||||
|
||||
use 5.008002;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Carp;
|
||||
use Excel::Writer::XLSX::Chart;
|
||||
|
||||
our @ISA = qw(Excel::Writer::XLSX::Chart);
|
||||
our $VERSION = '1.07';
|
||||
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# new()
|
||||
#
|
||||
#
|
||||
sub new {
|
||||
|
||||
my $class = shift;
|
||||
my $self = Excel::Writer::XLSX::Chart->new( @_ );
|
||||
|
||||
$self->{_subtype} = $self->{_subtype} || 'standard';
|
||||
$self->{_default_marker} = { type => 'none' };
|
||||
$self->{_smooth_allowed} = 1;
|
||||
|
||||
# Override and reset the default axis values.
|
||||
if ( $self->{_subtype} eq 'percent_stacked' ) {
|
||||
$self->{_y_axis}->{_defaults}->{num_format} = '0%';
|
||||
}
|
||||
|
||||
$self->set_y_axis();
|
||||
|
||||
# Set the available data label positions for this chart type.
|
||||
$self->{_label_position_default} = 'right';
|
||||
$self->{_label_positions} = {
|
||||
center => 'ctr',
|
||||
right => 'r',
|
||||
left => 'l',
|
||||
above => 't',
|
||||
below => 'b',
|
||||
# For backward compatibility.
|
||||
top => 't',
|
||||
bottom => 'b',
|
||||
};
|
||||
|
||||
bless $self, $class;
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_chart_type()
|
||||
#
|
||||
# Override the virtual superclass method with a chart specific method.
|
||||
#
|
||||
sub _write_chart_type {
|
||||
|
||||
my $self = shift;
|
||||
|
||||
# Write the c:lineChart element.
|
||||
$self->_write_line_chart( @_ );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_line_chart()
|
||||
#
|
||||
# Write the <c:lineChart> element.
|
||||
#
|
||||
sub _write_line_chart {
|
||||
|
||||
my $self = shift;
|
||||
my %args = @_;
|
||||
|
||||
my @series;
|
||||
if ( $args{primary_axes} ) {
|
||||
@series = $self->_get_primary_axes_series;
|
||||
}
|
||||
else {
|
||||
@series = $self->_get_secondary_axes_series;
|
||||
}
|
||||
|
||||
return unless scalar @series;
|
||||
|
||||
my $subtype = $self->{_subtype};
|
||||
|
||||
$subtype = 'percentStacked' if $subtype eq 'percent_stacked';
|
||||
|
||||
$self->xml_start_tag( 'c:lineChart' );
|
||||
|
||||
# Write the c:grouping element.
|
||||
$self->_write_grouping( $subtype );
|
||||
|
||||
# Write the series elements.
|
||||
$self->_write_series( $_ ) for @series;
|
||||
|
||||
# Write the c:dropLines element.
|
||||
$self->_write_drop_lines();
|
||||
|
||||
# Write the c:hiLowLines element.
|
||||
$self->_write_hi_low_lines();
|
||||
|
||||
# Write the c:upDownBars element.
|
||||
$self->_write_up_down_bars();
|
||||
|
||||
# Write the c:marker element.
|
||||
$self->_write_marker_value();
|
||||
|
||||
# Write the c:axId elements
|
||||
$self->_write_axis_ids( %args );
|
||||
|
||||
$self->xml_end_tag( 'c:lineChart' );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_d_pt_point()
|
||||
#
|
||||
# Write an individual <c:dPt> element. Override the parent method to add
|
||||
# markers.
|
||||
#
|
||||
sub _write_d_pt_point {
|
||||
|
||||
my $self = shift;
|
||||
my $index = shift;
|
||||
my $point = shift;
|
||||
|
||||
$self->xml_start_tag( 'c:dPt' );
|
||||
|
||||
# Write the c:idx element.
|
||||
$self->_write_idx( $index );
|
||||
|
||||
$self->xml_start_tag( 'c:marker' );
|
||||
|
||||
# Write the c:spPr element.
|
||||
$self->_write_sp_pr( $point );
|
||||
|
||||
$self->xml_end_tag( 'c:marker' );
|
||||
|
||||
$self->xml_end_tag( 'c:dPt' );
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_marker_value()
|
||||
#
|
||||
# Write the <c:marker> element without a sub-element.
|
||||
#
|
||||
sub _write_marker_value {
|
||||
|
||||
my $self = shift;
|
||||
|
||||
my @attributes = ( 'val' => 1 );
|
||||
|
||||
$self->xml_empty_tag( 'c:marker', @attributes );
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
||||
__END__
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Line - A class for writing Excel Line charts.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
To create a simple Excel file with a Line chart using Excel::Writer::XLSX:
|
||||
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Excel::Writer::XLSX;
|
||||
|
||||
my $workbook = Excel::Writer::XLSX->new( 'chart.xlsx' );
|
||||
my $worksheet = $workbook->add_worksheet();
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'line' );
|
||||
|
||||
# Configure the chart.
|
||||
$chart->add_series(
|
||||
categories => '=Sheet1!$A$2:$A$7',
|
||||
values => '=Sheet1!$B$2:$B$7',
|
||||
);
|
||||
|
||||
# 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__
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements Line charts for L<Excel::Writer::XLSX>. The chart object is created via the Workbook C<add_chart()> method:
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'line' );
|
||||
|
||||
Once the object is created it can be configured via the following methods that are common to all chart classes:
|
||||
|
||||
$chart->add_series();
|
||||
$chart->set_x_axis();
|
||||
$chart->set_y_axis();
|
||||
$chart->set_title();
|
||||
|
||||
These methods are explained in detail in L<Excel::Writer::XLSX::Chart>. Class specific methods or settings, if any, are explained below.
|
||||
|
||||
=head1 Line Chart Subtypes
|
||||
|
||||
|
||||
The C<Line> chart module also supports the following sub-types:
|
||||
|
||||
stacked
|
||||
percent_stacked
|
||||
|
||||
These can be specified at creation time via the C<add_chart()> Worksheet method:
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'line', subtype => 'stacked' );
|
||||
|
||||
=head1 EXAMPLE
|
||||
|
||||
Here is a complete example that demonstrates most of the available features when creating a chart.
|
||||
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Excel::Writer::XLSX;
|
||||
|
||||
my $workbook = Excel::Writer::XLSX->new( 'chart_line.xlsx' );
|
||||
my $worksheet = $workbook->add_worksheet();
|
||||
my $bold = $workbook->add_format( bold => 1 );
|
||||
|
||||
# Add the worksheet data that the charts will refer to.
|
||||
my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
|
||||
my $data = [
|
||||
[ 2, 3, 4, 5, 6, 7 ],
|
||||
[ 10, 40, 50, 20, 10, 50 ],
|
||||
[ 30, 60, 70, 50, 40, 30 ],
|
||||
|
||||
];
|
||||
|
||||
$worksheet->write( 'A1', $headings, $bold );
|
||||
$worksheet->write( 'A2', $data );
|
||||
|
||||
# Create a new chart object. In this case an embedded chart.
|
||||
my $chart = $workbook->add_chart( type => 'line', embedded => 1 );
|
||||
|
||||
# Configure the first series.
|
||||
$chart->add_series(
|
||||
name => '=Sheet1!$B$1',
|
||||
categories => '=Sheet1!$A$2:$A$7',
|
||||
values => '=Sheet1!$B$2:$B$7',
|
||||
);
|
||||
|
||||
# Configure second series. Note alternative use of array ref to define
|
||||
# ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
|
||||
$chart->add_series(
|
||||
name => '=Sheet1!$C$1',
|
||||
categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
||||
values => [ 'Sheet1', 1, 6, 2, 2 ],
|
||||
);
|
||||
|
||||
# Add a chart title and some axis labels.
|
||||
$chart->set_title ( name => 'Results of sample analysis' );
|
||||
$chart->set_x_axis( name => 'Test number' );
|
||||
$chart->set_y_axis( name => 'Sample length (mm)' );
|
||||
|
||||
# Set an Excel chart style. Colors with white outline and shadow.
|
||||
$chart->set_style( 10 );
|
||||
|
||||
# Insert the chart into the worksheet (with an offset).
|
||||
$worksheet->insert_chart( 'D2', $chart, 25, 10 );
|
||||
|
||||
__END__
|
||||
|
||||
|
||||
=begin html
|
||||
|
||||
<p>This will produce a chart that looks like this:</p>
|
||||
|
||||
<p><center><img src="http://jmcnamara.github.io/excel-writer-xlsx/images/examples/line1.jpg" width="483" height="291" alt="Chart example." /></center></p>
|
||||
|
||||
=end html
|
||||
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
John McNamara jmcnamara@cpan.org
|
||||
|
||||
=head1 COPYRIGHT
|
||||
|
||||
Copyright MM-MMXX, John McNamara.
|
||||
|
||||
All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
|
||||
514
database/perl/vendor/lib/Excel/Writer/XLSX/Chart/Pie.pm
vendored
Normal file
514
database/perl/vendor/lib/Excel/Writer/XLSX/Chart/Pie.pm
vendored
Normal file
@@ -0,0 +1,514 @@
|
||||
package Excel::Writer::XLSX::Chart::Pie;
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Pie - A class for writing Excel Pie charts.
|
||||
#
|
||||
# Used in conjunction with Excel::Writer::XLSX::Chart.
|
||||
#
|
||||
# See formatting note in Excel::Writer::XLSX::Chart.
|
||||
#
|
||||
# Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
|
||||
#
|
||||
# Documentation after __END__
|
||||
#
|
||||
|
||||
# perltidy with the following options: -mbl=2 -pt=0 -nola
|
||||
|
||||
use 5.008002;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Carp;
|
||||
use Excel::Writer::XLSX::Chart;
|
||||
|
||||
our @ISA = qw(Excel::Writer::XLSX::Chart);
|
||||
our $VERSION = '1.07';
|
||||
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# new()
|
||||
#
|
||||
#
|
||||
sub new {
|
||||
|
||||
my $class = shift;
|
||||
my $self = Excel::Writer::XLSX::Chart->new( @_ );
|
||||
|
||||
$self->{_vary_data_color} = 1;
|
||||
$self->{_rotation} = 0;
|
||||
|
||||
# Set the available data label positions for this chart type.
|
||||
$self->{_label_position_default} = 'best_fit';
|
||||
$self->{_label_positions} = {
|
||||
center => 'ctr',
|
||||
inside_end => 'inEnd',
|
||||
outside_end => 'outEnd',
|
||||
best_fit => 'bestFit',
|
||||
};
|
||||
|
||||
bless $self, $class;
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# set_rotation()
|
||||
#
|
||||
# Set the Pie/Doughnut chart rotation: the angle of the first slice.
|
||||
#
|
||||
sub set_rotation {
|
||||
|
||||
my $self = shift;
|
||||
my $rotation = shift;
|
||||
|
||||
return if !defined $rotation;
|
||||
|
||||
if ( $rotation >= 0 && $rotation <= 360 ) {
|
||||
$self->{_rotation} = $rotation;
|
||||
}
|
||||
else {
|
||||
carp "Chart rotation $rotation outside range: 0 <= rotation <= 360";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_chart_type()
|
||||
#
|
||||
# Override the virtual superclass method with a chart specific method.
|
||||
#
|
||||
sub _write_chart_type {
|
||||
|
||||
my $self = shift;
|
||||
|
||||
# Write the c:pieChart element.
|
||||
$self->_write_pie_chart( @_ );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_pie_chart()
|
||||
#
|
||||
# Write the <c:pieChart> element. Over-ridden method to remove axis_id code
|
||||
# since Pie charts don't require val and cat axes.
|
||||
#
|
||||
sub _write_pie_chart {
|
||||
|
||||
my $self = shift;
|
||||
|
||||
$self->xml_start_tag( 'c:pieChart' );
|
||||
|
||||
# Write the c:varyColors element.
|
||||
$self->_write_vary_colors();
|
||||
|
||||
# Write the series elements.
|
||||
$self->_write_ser( $_ ) for @{ $self->{_series} };
|
||||
|
||||
# Write the c:firstSliceAng element.
|
||||
$self->_write_first_slice_ang();
|
||||
|
||||
$self->xml_end_tag( 'c:pieChart' );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_plot_area().
|
||||
#
|
||||
# Over-ridden method to remove the cat_axis() and val_axis() code since
|
||||
# Pie/Doughnut charts don't require those axes.
|
||||
#
|
||||
# Write the <c:plotArea> element.
|
||||
#
|
||||
sub _write_plot_area {
|
||||
|
||||
my $self = shift;
|
||||
my $second_chart = $self->{_combined};
|
||||
|
||||
$self->xml_start_tag( 'c:plotArea' );
|
||||
|
||||
# Write the c:layout element.
|
||||
$self->_write_layout( $self->{_plotarea}->{_layout}, 'plot' );
|
||||
|
||||
# Write the subclass chart type element.
|
||||
$self->_write_chart_type();
|
||||
|
||||
# Configure a combined chart if present.
|
||||
if ( $second_chart ) {
|
||||
|
||||
# Secondary axis has unique id otherwise use same as primary.
|
||||
if ( $second_chart->{_is_secondary} ) {
|
||||
$second_chart->{_id} = 1000 + $self->{_id};
|
||||
}
|
||||
else {
|
||||
$second_chart->{_id} = $self->{_id};
|
||||
}
|
||||
|
||||
# Shart the same filehandle for writing.
|
||||
$second_chart->{_fh} = $self->{_fh};
|
||||
|
||||
# Share series index with primary chart.
|
||||
$second_chart->{_series_index} = $self->{_series_index};
|
||||
|
||||
# Write the subclass chart type elements for combined chart.
|
||||
$second_chart->_write_chart_type();
|
||||
}
|
||||
|
||||
# Write the c:spPr element for the plotarea formatting.
|
||||
$self->_write_sp_pr( $self->{_plotarea} );
|
||||
|
||||
$self->xml_end_tag( 'c:plotArea' );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_legend().
|
||||
#
|
||||
# Over-ridden method to add <c:txPr> to legend.
|
||||
#
|
||||
# Write the <c:legend> element.
|
||||
#
|
||||
sub _write_legend {
|
||||
|
||||
my $self = shift;
|
||||
my $legend = $self->{_legend};
|
||||
my $position = $legend->{_position} || 'right';
|
||||
my $font = $legend->{_font};
|
||||
my @delete_series = ();
|
||||
my $overlay = 0;
|
||||
|
||||
if ( defined $legend->{_delete_series}
|
||||
&& ref $legend->{_delete_series} eq 'ARRAY' )
|
||||
{
|
||||
@delete_series = @{ $legend->{_delete_series} };
|
||||
}
|
||||
|
||||
if ( $position =~ s/^overlay_// ) {
|
||||
$overlay = 1;
|
||||
}
|
||||
|
||||
my %allowed = (
|
||||
right => 'r',
|
||||
left => 'l',
|
||||
top => 't',
|
||||
bottom => 'b',
|
||||
top_right => 'tr',
|
||||
);
|
||||
|
||||
return if $position eq 'none';
|
||||
return unless exists $allowed{$position};
|
||||
|
||||
$position = $allowed{$position};
|
||||
|
||||
$self->xml_start_tag( 'c:legend' );
|
||||
|
||||
# Write the c:legendPos element.
|
||||
$self->_write_legend_pos( $position );
|
||||
|
||||
# Remove series labels from the legend.
|
||||
for my $index ( @delete_series ) {
|
||||
|
||||
# Write the c:legendEntry element.
|
||||
$self->_write_legend_entry( $index );
|
||||
}
|
||||
|
||||
# Write the c:layout element.
|
||||
$self->_write_layout( $legend->{_layout}, 'legend' );
|
||||
|
||||
# Write the c:overlay element.
|
||||
$self->_write_overlay() if $overlay;
|
||||
|
||||
# Write the c:spPr element.
|
||||
$self->_write_sp_pr( $legend );
|
||||
|
||||
# Write the c:txPr element. Over-ridden.
|
||||
$self->_write_tx_pr_legend( 0, $font );
|
||||
|
||||
$self->xml_end_tag( 'c:legend' );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_tx_pr_legend()
|
||||
#
|
||||
# Write the <c:txPr> element for legends.
|
||||
#
|
||||
sub _write_tx_pr_legend {
|
||||
|
||||
my $self = shift;
|
||||
my $horiz = shift;
|
||||
my $font = shift;
|
||||
my $rotation = undef;
|
||||
|
||||
if ( $font && exists $font->{_rotation} ) {
|
||||
$rotation = $font->{_rotation};
|
||||
}
|
||||
|
||||
$self->xml_start_tag( 'c:txPr' );
|
||||
|
||||
# Write the a:bodyPr element.
|
||||
$self->_write_a_body_pr( $rotation, $horiz );
|
||||
|
||||
# Write the a:lstStyle element.
|
||||
$self->_write_a_lst_style();
|
||||
|
||||
# Write the a:p element.
|
||||
$self->_write_a_p_legend( $font );
|
||||
|
||||
$self->xml_end_tag( 'c:txPr' );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_a_p_legend()
|
||||
#
|
||||
# Write the <a:p> element for legends.
|
||||
#
|
||||
sub _write_a_p_legend {
|
||||
|
||||
my $self = shift;
|
||||
my $font = shift;
|
||||
|
||||
$self->xml_start_tag( 'a:p' );
|
||||
|
||||
# Write the a:pPr element.
|
||||
$self->_write_a_p_pr_legend( $font );
|
||||
|
||||
# Write the a:endParaRPr element.
|
||||
$self->_write_a_end_para_rpr();
|
||||
|
||||
$self->xml_end_tag( 'a:p' );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_a_p_pr_legend()
|
||||
#
|
||||
# Write the <a:pPr> element for legends.
|
||||
#
|
||||
sub _write_a_p_pr_legend {
|
||||
|
||||
my $self = shift;
|
||||
my $font = shift;
|
||||
my $rtl = 0;
|
||||
|
||||
my @attributes = ( 'rtl' => $rtl );
|
||||
|
||||
$self->xml_start_tag( 'a:pPr', @attributes );
|
||||
|
||||
# Write the a:defRPr element.
|
||||
$self->_write_a_def_rpr( $font );
|
||||
|
||||
$self->xml_end_tag( 'a:pPr' );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_vary_colors()
|
||||
#
|
||||
# Write the <c:varyColors> element.
|
||||
#
|
||||
sub _write_vary_colors {
|
||||
|
||||
my $self = shift;
|
||||
my $val = 1;
|
||||
|
||||
my @attributes = ( 'val' => $val );
|
||||
|
||||
$self->xml_empty_tag( 'c:varyColors', @attributes );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_first_slice_ang()
|
||||
#
|
||||
# Write the <c:firstSliceAng> element.
|
||||
#
|
||||
sub _write_first_slice_ang {
|
||||
|
||||
my $self = shift;
|
||||
my $val = $self->{_rotation};
|
||||
|
||||
my @attributes = ( 'val' => $val );
|
||||
|
||||
$self->xml_empty_tag( 'c:firstSliceAng', @attributes );
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
||||
__END__
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Pie - A class for writing Excel Pie charts.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
To create a simple Excel file with a Pie chart using Excel::Writer::XLSX:
|
||||
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Excel::Writer::XLSX;
|
||||
|
||||
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',
|
||||
);
|
||||
|
||||
# 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__
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements Pie charts for L<Excel::Writer::XLSX>. The chart object is created via the Workbook C<add_chart()> method:
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'pie' );
|
||||
|
||||
Once the object is created it can be configured via the following methods that are common to all chart classes:
|
||||
|
||||
$chart->add_series();
|
||||
$chart->set_title();
|
||||
|
||||
These methods are explained in detail in L<Excel::Writer::XLSX::Chart>. Class specific methods or settings, if any, are explained below.
|
||||
|
||||
=head1 Pie Chart Methods
|
||||
|
||||
=head2 set_rotation()
|
||||
|
||||
The C<set_rotation()> method is used to set the rotation of the first segment of a Pie/Doughnut chart. This has the effect of rotating the entire chart:
|
||||
|
||||
$chart->set_rotation( 90 );
|
||||
|
||||
The angle of rotation must be C<< 0 <= rotation <= 360 >>.
|
||||
|
||||
|
||||
=head2 User defined colors
|
||||
|
||||
It is possible to define chart colors for most types of Excel::Writer::XLSX charts via the add_series() method. However, Pie/Doughnut charts are a special case since each segment is represented as a point so it is necessary to assign formatting to each point in the series:
|
||||
|
||||
$chart->add_series(
|
||||
values => '=Sheet1!$A$1:$A$3',
|
||||
points => [
|
||||
{ fill => { color => '#FF0000' } },
|
||||
{ fill => { color => '#CC0000' } },
|
||||
{ fill => { color => '#990000' } },
|
||||
],
|
||||
);
|
||||
|
||||
See the main L<Excel::Writer::XLSX::Chart> documentation for more details.
|
||||
|
||||
Pie charts support leader lines:
|
||||
|
||||
$chart->add_series(
|
||||
name => 'Pie sales data',
|
||||
categories => [ 'Sheet1', 1, 3, 0, 0 ],
|
||||
values => [ 'Sheet1', 1, 3, 1, 1 ],
|
||||
data_labels => {
|
||||
series_name => 1,
|
||||
percentage => 1,
|
||||
leader_lines => 1,
|
||||
position => 'outside_end'
|
||||
},
|
||||
);
|
||||
|
||||
Note: Even when leader lines are turned on they aren't automatically visible in Excel or Excel::Writer::XLSX. 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.
|
||||
|
||||
=head2 Unsupported Methods
|
||||
|
||||
A Pie chart doesn't have an X or Y axis so the following common chart methods are ignored.
|
||||
|
||||
$chart->set_x_axis();
|
||||
$chart->set_y_axis();
|
||||
|
||||
=head1 EXAMPLE
|
||||
|
||||
Here is a complete example that demonstrates most of the available features when creating a chart.
|
||||
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Excel::Writer::XLSX;
|
||||
|
||||
my $workbook = Excel::Writer::XLSX->new( 'chart_pie.xlsx' );
|
||||
my $worksheet = $workbook->add_worksheet();
|
||||
my $bold = $workbook->add_format( 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->add_chart( type => 'pie', embedded => 1 );
|
||||
|
||||
# Configure the series. Note the use of the array ref to define ranges:
|
||||
# [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
|
||||
$chart->add_series(
|
||||
name => 'Pie sales data',
|
||||
categories => [ 'Sheet1', 1, 3, 0, 0 ],
|
||||
values => [ 'Sheet1', 1, 3, 1, 1 ],
|
||||
);
|
||||
|
||||
# Add a title.
|
||||
$chart->set_title( name => 'Popular Pie Types' );
|
||||
|
||||
# Set an Excel chart style. Colors with white outline and shadow.
|
||||
$chart->set_style( 10 );
|
||||
|
||||
# Insert the chart into the worksheet (with an offset).
|
||||
$worksheet->insert_chart( 'C2', $chart, 25, 10 );
|
||||
|
||||
__END__
|
||||
|
||||
|
||||
=begin html
|
||||
|
||||
<p>This will produce a chart that looks like this:</p>
|
||||
|
||||
<p><center><img src="http://jmcnamara.github.io/excel-writer-xlsx/images/examples/pie1.jpg" width="483" height="291" alt="Chart example." /></center></p>
|
||||
|
||||
=end html
|
||||
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
John McNamara jmcnamara@cpan.org
|
||||
|
||||
=head1 COPYRIGHT
|
||||
|
||||
Copyright MM-MMXX, John McNamara.
|
||||
|
||||
All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
|
||||
275
database/perl/vendor/lib/Excel/Writer/XLSX/Chart/Radar.pm
vendored
Normal file
275
database/perl/vendor/lib/Excel/Writer/XLSX/Chart/Radar.pm
vendored
Normal file
@@ -0,0 +1,275 @@
|
||||
package Excel::Writer::XLSX::Chart::Radar;
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Radar - A class for writing Excel Radar charts.
|
||||
#
|
||||
# Used in conjunction with Excel::Writer::XLSX::Chart.
|
||||
#
|
||||
# See formatting note in Excel::Writer::XLSX::Chart.
|
||||
#
|
||||
# Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
|
||||
#
|
||||
# Documentation after __END__
|
||||
#
|
||||
|
||||
# perltidy with the following options: -mbl=2 -pt=0 -nola
|
||||
|
||||
use 5.008002;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Carp;
|
||||
use Excel::Writer::XLSX::Chart;
|
||||
|
||||
our @ISA = qw(Excel::Writer::XLSX::Chart);
|
||||
our $VERSION = '1.07';
|
||||
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# new()
|
||||
#
|
||||
#
|
||||
sub new {
|
||||
|
||||
my $class = shift;
|
||||
my $self = Excel::Writer::XLSX::Chart->new( @_ );
|
||||
|
||||
$self->{_subtype} = $self->{_subtype} || 'marker';
|
||||
|
||||
if ( $self->{_subtype} eq 'marker' ) {
|
||||
$self->{_default_marker} = { type => 'none' };
|
||||
}
|
||||
|
||||
# Override and reset the default axis values.
|
||||
$self->{_x_axis}->{_defaults}->{major_gridlines} = { visible => 1 };
|
||||
$self->set_x_axis();
|
||||
|
||||
# Hardcode major_tick_mark for now until there is an accessor.
|
||||
$self->{_y_axis}->{_major_tick_mark} = 'cross';
|
||||
|
||||
# Set the available data label positions for this chart type.
|
||||
$self->{_label_position_default} = 'center';
|
||||
$self->{_label_positions} = { center => 'ctr' };
|
||||
|
||||
bless $self, $class;
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_chart_type()
|
||||
#
|
||||
# Override the virtual superclass method with a chart specific method.
|
||||
#
|
||||
sub _write_chart_type {
|
||||
|
||||
my $self = shift;
|
||||
|
||||
# Write the c:radarChart element.
|
||||
$self->_write_radar_chart( @_ );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_radar_chart()
|
||||
#
|
||||
# Write the <c:radarChart> element.
|
||||
#
|
||||
sub _write_radar_chart {
|
||||
|
||||
my $self = shift;
|
||||
my %args = @_;
|
||||
|
||||
my @series;
|
||||
if ( $args{primary_axes} ) {
|
||||
@series = $self->_get_primary_axes_series;
|
||||
}
|
||||
else {
|
||||
@series = $self->_get_secondary_axes_series;
|
||||
}
|
||||
|
||||
return unless scalar @series;
|
||||
|
||||
$self->xml_start_tag( 'c:radarChart' );
|
||||
|
||||
# Write the c:radarStyle element.
|
||||
$self->_write_radar_style();
|
||||
|
||||
# Write the series elements.
|
||||
$self->_write_series( $_ ) for @series;
|
||||
|
||||
# Write the c:axId elements
|
||||
$self->_write_axis_ids( %args );
|
||||
|
||||
$self->xml_end_tag( 'c:radarChart' );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_radar_style()
|
||||
#
|
||||
# Write the <c:radarStyle> element.
|
||||
#
|
||||
sub _write_radar_style {
|
||||
|
||||
my $self = shift;
|
||||
my $val = 'marker';
|
||||
|
||||
if ( $self->{_subtype} eq 'filled' ) {
|
||||
$val = 'filled';
|
||||
}
|
||||
|
||||
my @attributes = ( 'val' => $val );
|
||||
|
||||
$self->xml_empty_tag( 'c:radarStyle', @attributes );
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
||||
__END__
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Radar - A class for writing Excel Radar charts.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
To create a simple Excel file with a Radar chart using Excel::Writer::XLSX:
|
||||
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Excel::Writer::XLSX;
|
||||
|
||||
my $workbook = Excel::Writer::XLSX->new( 'chart.xlsx' );
|
||||
my $worksheet = $workbook->add_worksheet();
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'radar' );
|
||||
|
||||
# Configure the chart.
|
||||
$chart->add_series(
|
||||
categories => '=Sheet1!$A$2:$A$7',
|
||||
values => '=Sheet1!$B$2:$B$7',
|
||||
);
|
||||
|
||||
# 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__
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements Radar charts for L<Excel::Writer::XLSX>. The chart object is created via the Workbook C<add_chart()> method:
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'radar' );
|
||||
|
||||
Once the object is created it can be configured via the following methods that are common to all chart classes:
|
||||
|
||||
$chart->add_series();
|
||||
$chart->set_x_axis();
|
||||
$chart->set_y_axis();
|
||||
$chart->set_title();
|
||||
|
||||
These methods are explained in detail in L<Excel::Writer::XLSX::Chart>. Class specific methods or settings, if any, are explained below.
|
||||
|
||||
=head1 Radar Chart Methods
|
||||
|
||||
The C<Radar> chart module also supports the following sub-types:
|
||||
|
||||
with_markers
|
||||
filled
|
||||
|
||||
These can be specified at creation time via the C<add_chart()> Worksheet method:
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'radar', subtype => 'filled' );
|
||||
|
||||
=head1 EXAMPLE
|
||||
|
||||
Here is a complete example that demonstrates most of the available features when creating a chart.
|
||||
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Excel::Writer::XLSX;
|
||||
|
||||
my $workbook = Excel::Writer::XLSX->new( 'chart_radar.xlsx' );
|
||||
my $worksheet = $workbook->add_worksheet();
|
||||
my $bold = $workbook->add_format( bold => 1 );
|
||||
|
||||
# Add the worksheet data that the charts will refer to.
|
||||
my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
|
||||
my $data = [
|
||||
[ 2, 3, 4, 5, 6, 7 ],
|
||||
[ 30, 60, 70, 50, 40, 30 ],
|
||||
[ 25, 40, 50, 30, 50, 40 ],
|
||||
|
||||
];
|
||||
|
||||
$worksheet->write( 'A1', $headings, $bold );
|
||||
$worksheet->write( 'A2', $data );
|
||||
|
||||
# Create a new chart object. In this case an embedded chart.
|
||||
my $chart = $workbook->add_chart( type => 'radar', embedded => 1 );
|
||||
|
||||
# Configure the first series.
|
||||
$chart->add_series(
|
||||
name => '=Sheet1!$B$1',
|
||||
categories => '=Sheet1!$A$2:$A$7',
|
||||
values => '=Sheet1!$B$2:$B$7',
|
||||
);
|
||||
|
||||
# Configure second series. Note alternative use of array ref to define
|
||||
# ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
|
||||
$chart->add_series(
|
||||
name => '=Sheet1!$C$1',
|
||||
categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
||||
values => [ 'Sheet1', 1, 6, 2, 2 ],
|
||||
);
|
||||
|
||||
# Add a chart title and some axis labels.
|
||||
$chart->set_title ( name => 'Results of sample analysis' );
|
||||
$chart->set_x_axis( name => 'Test number' );
|
||||
$chart->set_y_axis( name => 'Sample length (mm)' );
|
||||
|
||||
# Set an Excel chart style. Colors with white outline and shadow.
|
||||
$chart->set_style( 10 );
|
||||
|
||||
# Insert the chart into the worksheet (with an offset).
|
||||
$worksheet->insert_chart( 'D2', $chart, 25, 10 );
|
||||
|
||||
__END__
|
||||
|
||||
|
||||
=begin html
|
||||
|
||||
<p>This will produce a chart that looks like this:</p>
|
||||
|
||||
<p><center><img src="http://jmcnamara.github.io/excel-writer-xlsx/images/examples/radar1.jpg" width="483" height="291" alt="Chart example." /></center></p>
|
||||
|
||||
=end html
|
||||
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
John McNamara jmcnamara@cpan.org
|
||||
|
||||
=head1 COPYRIGHT
|
||||
|
||||
Copyright MM-MMXX, John McNamara.
|
||||
|
||||
All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
|
||||
571
database/perl/vendor/lib/Excel/Writer/XLSX/Chart/Scatter.pm
vendored
Normal file
571
database/perl/vendor/lib/Excel/Writer/XLSX/Chart/Scatter.pm
vendored
Normal file
@@ -0,0 +1,571 @@
|
||||
package Excel::Writer::XLSX::Chart::Scatter;
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Scatter - A class for writing Excel Scatter charts.
|
||||
#
|
||||
# Used in conjunction with Excel::Writer::XLSX::Chart.
|
||||
#
|
||||
# See formatting note in Excel::Writer::XLSX::Chart.
|
||||
#
|
||||
# Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
|
||||
#
|
||||
# Documentation after __END__
|
||||
#
|
||||
|
||||
# perltidy with the following options: -mbl=2 -pt=0 -nola
|
||||
|
||||
use 5.008002;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Carp;
|
||||
use Excel::Writer::XLSX::Chart;
|
||||
|
||||
our @ISA = qw(Excel::Writer::XLSX::Chart);
|
||||
our $VERSION = '1.07';
|
||||
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# new()
|
||||
#
|
||||
#
|
||||
sub new {
|
||||
|
||||
my $class = shift;
|
||||
my $self = Excel::Writer::XLSX::Chart->new( @_ );
|
||||
|
||||
$self->{_subtype} = $self->{_subtype} || 'marker_only';
|
||||
$self->{_cross_between} = 'midCat';
|
||||
$self->{_horiz_val_axis} = 0;
|
||||
$self->{_val_axis_postion} = 'b';
|
||||
$self->{_smooth_allowed} = 1;
|
||||
$self->{_requires_category} = 1;
|
||||
|
||||
# Set the available data label positions for this chart type.
|
||||
$self->{_label_position_default} = 'right';
|
||||
$self->{_label_positions} = {
|
||||
center => 'ctr',
|
||||
right => 'r',
|
||||
left => 'l',
|
||||
above => 't',
|
||||
below => 'b',
|
||||
# For backward compatibility.
|
||||
top => 't',
|
||||
bottom => 'b',
|
||||
};
|
||||
|
||||
bless $self, $class;
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# combine()
|
||||
#
|
||||
# Override parent method to add a warning.
|
||||
#
|
||||
sub combine {
|
||||
|
||||
my $self = shift;
|
||||
my $chart = shift;
|
||||
|
||||
carp 'Combined chart not currently supported with scatter chart ' .
|
||||
'as the primary chart';
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_chart_type()
|
||||
#
|
||||
# Override the virtual superclass method with a chart specific method.
|
||||
#
|
||||
sub _write_chart_type {
|
||||
|
||||
my $self = shift;
|
||||
|
||||
# Write the c:scatterChart element.
|
||||
$self->_write_scatter_chart( @_ );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_scatter_chart()
|
||||
#
|
||||
# Write the <c:scatterChart> element.
|
||||
#
|
||||
sub _write_scatter_chart {
|
||||
|
||||
my $self = shift;
|
||||
my %args = @_;
|
||||
|
||||
my @series;
|
||||
if ( $args{primary_axes} ) {
|
||||
@series = $self->_get_primary_axes_series;
|
||||
}
|
||||
else {
|
||||
@series = $self->_get_secondary_axes_series;
|
||||
}
|
||||
|
||||
return unless scalar @series;
|
||||
|
||||
my $style = 'lineMarker';
|
||||
my $subtype = $self->{_subtype};
|
||||
|
||||
# Set the user defined chart subtype.
|
||||
|
||||
if ($subtype eq 'marker_only') {
|
||||
$style = 'lineMarker';
|
||||
}
|
||||
|
||||
if ($subtype eq 'straight_with_markers') {
|
||||
$style = 'lineMarker';
|
||||
}
|
||||
|
||||
if ($subtype eq 'straight') {
|
||||
$style = 'lineMarker';
|
||||
$self->{_default_marker} = { type => 'none' };
|
||||
}
|
||||
|
||||
if ($subtype eq 'smooth_with_markers') {
|
||||
$style = 'smoothMarker';
|
||||
}
|
||||
|
||||
if ($subtype eq 'smooth') {
|
||||
$style = 'smoothMarker';
|
||||
$self->{_default_marker} = { type => 'none' };
|
||||
}
|
||||
|
||||
# Add default formatting to the series data.
|
||||
$self->_modify_series_formatting();
|
||||
|
||||
$self->xml_start_tag( 'c:scatterChart' );
|
||||
|
||||
# Write the c:scatterStyle element.
|
||||
$self->_write_scatter_style( $style );
|
||||
|
||||
# Write the series elements.
|
||||
$self->_write_ser( $_ ) for @series;
|
||||
|
||||
# Write the c:axId elements
|
||||
$self->_write_axis_ids( %args );
|
||||
|
||||
$self->xml_end_tag( 'c:scatterChart' );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_ser()
|
||||
#
|
||||
# Over-ridden to write c:xVal/c:yVal instead of c:cat/c:val elements.
|
||||
#
|
||||
# Write the <c:ser> element.
|
||||
#
|
||||
sub _write_ser {
|
||||
|
||||
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: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:xVal element.
|
||||
$self->_write_x_val( $series );
|
||||
|
||||
# Write the c:yVal element.
|
||||
$self->_write_y_val( $series );
|
||||
|
||||
# Write the c:smooth element.
|
||||
if ( $self->{_subtype} =~ /smooth/ && !defined $series->{_smooth} ) {
|
||||
# Default is on for smooth scatter charts.
|
||||
$self->_write_c_smooth( 1 );
|
||||
}
|
||||
else {
|
||||
$self->_write_c_smooth( $series->{_smooth} );
|
||||
}
|
||||
|
||||
$self->xml_end_tag( 'c:ser' );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_plot_area()
|
||||
#
|
||||
# Over-ridden to have 2 valAx elements for scatter charts instead of
|
||||
# catAx/valAx.
|
||||
#
|
||||
# Write the <c:plotArea> element.
|
||||
#
|
||||
sub _write_plot_area {
|
||||
|
||||
my $self = shift;
|
||||
|
||||
$self->xml_start_tag( 'c:plotArea' );
|
||||
|
||||
# Write the c:layout element.
|
||||
$self->_write_layout( $self->{_plotarea}->{_layout}, 'plot' );
|
||||
|
||||
# Write the subclass chart type elements for primary and secondary axes.
|
||||
$self->_write_chart_type( primary_axes => 1 );
|
||||
$self->_write_chart_type( primary_axes => 0 );
|
||||
|
||||
# Write c:catAx and c:valAx elements for series using primary axes.
|
||||
$self->_write_cat_val_axis(
|
||||
x_axis => $self->{_x_axis},
|
||||
y_axis => $self->{_y_axis},
|
||||
axis_ids => $self->{_axis_ids},
|
||||
position => 'b',
|
||||
);
|
||||
|
||||
my $tmp = $self->{_horiz_val_axis};
|
||||
$self->{_horiz_val_axis} = 1;
|
||||
$self->_write_val_axis(
|
||||
x_axis => $self->{_x_axis},
|
||||
y_axis => $self->{_y_axis},
|
||||
axis_ids => $self->{_axis_ids},
|
||||
position => 'l',
|
||||
);
|
||||
$self->{_horiz_val_axis} = $tmp;
|
||||
|
||||
# Write c:valAx and c:catAx elements for series using secondary axes.
|
||||
$self->_write_cat_val_axis(
|
||||
x_axis => $self->{_x2_axis},
|
||||
y_axis => $self->{_y2_axis},
|
||||
axis_ids => $self->{_axis2_ids},
|
||||
position => 'b',
|
||||
);
|
||||
$self->{_horiz_val_axis} = 1;
|
||||
$self->_write_val_axis(
|
||||
x_axis => $self->{_x2_axis},
|
||||
y_axis => $self->{_y2_axis},
|
||||
axis_ids => $self->{_axis2_ids},
|
||||
position => 'l',
|
||||
);
|
||||
|
||||
# Write the c:spPr element for the plotarea formatting.
|
||||
$self->_write_sp_pr( $self->{_plotarea} );
|
||||
|
||||
$self->xml_end_tag( 'c:plotArea' );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_x_val()
|
||||
#
|
||||
# Write the <c:xVal> element.
|
||||
#
|
||||
sub _write_x_val {
|
||||
|
||||
my $self = shift;
|
||||
my $series = shift;
|
||||
my $formula = $series->{_categories};
|
||||
my $data_id = $series->{_cat_data_id};
|
||||
my $data = $self->{_formula_data}->[$data_id];
|
||||
|
||||
$self->xml_start_tag( 'c:xVal' );
|
||||
|
||||
# Check the type of cached data.
|
||||
my $type = $self->_get_data_type( $data );
|
||||
|
||||
# TODO. Can a scatter plot have non-numeric data.
|
||||
|
||||
if ( $type eq 'str' ) {
|
||||
|
||||
# Write the c:numRef element.
|
||||
$self->_write_str_ref( $formula, $data, $type );
|
||||
}
|
||||
else {
|
||||
|
||||
# Write the c:numRef element.
|
||||
$self->_write_num_ref( $formula, $data, $type );
|
||||
}
|
||||
|
||||
$self->xml_end_tag( 'c:xVal' );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_y_val()
|
||||
#
|
||||
# Write the <c:yVal> element.
|
||||
#
|
||||
sub _write_y_val {
|
||||
|
||||
my $self = shift;
|
||||
my $series = shift;
|
||||
my $formula = $series->{_values};
|
||||
my $data_id = $series->{_val_data_id};
|
||||
my $data = $self->{_formula_data}->[$data_id];
|
||||
|
||||
$self->xml_start_tag( 'c:yVal' );
|
||||
|
||||
# Unlike Cat axes data should only be numeric.
|
||||
|
||||
# Write the c:numRef element.
|
||||
$self->_write_num_ref( $formula, $data, 'num' );
|
||||
|
||||
$self->xml_end_tag( 'c:yVal' );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_scatter_style()
|
||||
#
|
||||
# Write the <c:scatterStyle> element.
|
||||
#
|
||||
sub _write_scatter_style {
|
||||
|
||||
my $self = shift;
|
||||
my $val = shift;
|
||||
|
||||
my @attributes = ( 'val' => $val );
|
||||
|
||||
$self->xml_empty_tag( 'c:scatterStyle', @attributes );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _modify_series_formatting()
|
||||
#
|
||||
# Add default formatting to the series data unless it has already been
|
||||
# specified by the user.
|
||||
#
|
||||
sub _modify_series_formatting {
|
||||
|
||||
my $self = shift;
|
||||
my $subtype = $self->{_subtype};
|
||||
|
||||
# The default scatter style "markers only" requires a line type.
|
||||
if ( $subtype eq 'marker_only' ) {
|
||||
|
||||
# Go through each series and define default values.
|
||||
for my $series ( @{ $self->{_series} } ) {
|
||||
|
||||
# Set a line type unless there is already a user defined type.
|
||||
if ( !$series->{_line}->{_defined} ) {
|
||||
$series->{_line} = {
|
||||
width => 2.25,
|
||||
none => 1,
|
||||
_defined => 1,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_d_pt_point()
|
||||
#
|
||||
# Write an individual <c:dPt> element. Override the parent method to add
|
||||
# markers.
|
||||
#
|
||||
sub _write_d_pt_point {
|
||||
|
||||
my $self = shift;
|
||||
my $index = shift;
|
||||
my $point = shift;
|
||||
|
||||
$self->xml_start_tag( 'c:dPt' );
|
||||
|
||||
# Write the c:idx element.
|
||||
$self->_write_idx( $index );
|
||||
|
||||
$self->xml_start_tag( 'c:marker' );
|
||||
|
||||
# Write the c:spPr element.
|
||||
$self->_write_sp_pr( $point );
|
||||
|
||||
$self->xml_end_tag( 'c:marker' );
|
||||
|
||||
$self->xml_end_tag( 'c:dPt' );
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
||||
__END__
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Scatter - A class for writing Excel Scatter charts.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
To create a simple Excel file with a Scatter chart using Excel::Writer::XLSX:
|
||||
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Excel::Writer::XLSX;
|
||||
|
||||
my $workbook = Excel::Writer::XLSX->new( 'chart.xlsx' );
|
||||
my $worksheet = $workbook->add_worksheet();
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'scatter' );
|
||||
|
||||
# Configure the chart.
|
||||
$chart->add_series(
|
||||
categories => '=Sheet1!$A$2:$A$7',
|
||||
values => '=Sheet1!$B$2:$B$7',
|
||||
);
|
||||
|
||||
# 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__
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements Scatter charts for L<Excel::Writer::XLSX>. The chart object is created via the Workbook C<add_chart()> method:
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'scatter' );
|
||||
|
||||
Once the object is created it can be configured via the following methods that are common to all chart classes:
|
||||
|
||||
$chart->add_series();
|
||||
$chart->set_x_axis();
|
||||
$chart->set_y_axis();
|
||||
$chart->set_title();
|
||||
|
||||
These methods are explained in detail in L<Excel::Writer::XLSX::Chart>. Class specific methods or settings, if any, are explained below.
|
||||
|
||||
=head1 Scatter Chart Subtypes
|
||||
|
||||
The C<Scatter> chart module also supports the following sub-types:
|
||||
|
||||
markers_only (the default)
|
||||
straight_with_markers
|
||||
straight
|
||||
smooth_with_markers
|
||||
smooth
|
||||
|
||||
These can be specified at creation time via the C<add_chart()> Worksheet method:
|
||||
|
||||
my $chart = $workbook->add_chart(
|
||||
type => 'scatter',
|
||||
subtype => 'straight_with_markers'
|
||||
);
|
||||
|
||||
=head1 EXAMPLE
|
||||
|
||||
Here is a complete example that demonstrates most of the available features when creating a chart.
|
||||
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Excel::Writer::XLSX;
|
||||
|
||||
my $workbook = Excel::Writer::XLSX->new( 'chart_scatter.xlsx' );
|
||||
my $worksheet = $workbook->add_worksheet();
|
||||
my $bold = $workbook->add_format( bold => 1 );
|
||||
|
||||
# Add the worksheet data that the charts will refer to.
|
||||
my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
|
||||
my $data = [
|
||||
[ 2, 3, 4, 5, 6, 7 ],
|
||||
[ 10, 40, 50, 20, 10, 50 ],
|
||||
[ 30, 60, 70, 50, 40, 30 ],
|
||||
|
||||
];
|
||||
|
||||
$worksheet->write( 'A1', $headings, $bold );
|
||||
$worksheet->write( 'A2', $data );
|
||||
|
||||
# Create a new chart object. In this case an embedded chart.
|
||||
my $chart = $workbook->add_chart( type => 'scatter', embedded => 1 );
|
||||
|
||||
# Configure the first series.
|
||||
$chart->add_series(
|
||||
name => '=Sheet1!$B$1',
|
||||
categories => '=Sheet1!$A$2:$A$7',
|
||||
values => '=Sheet1!$B$2:$B$7',
|
||||
);
|
||||
|
||||
# Configure second series. Note alternative use of array ref to define
|
||||
# ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
|
||||
$chart->add_series(
|
||||
name => '=Sheet1!$C$1',
|
||||
categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
||||
values => [ 'Sheet1', 1, 6, 2, 2 ],
|
||||
);
|
||||
|
||||
# Add a chart title and some axis labels.
|
||||
$chart->set_title ( name => 'Results of sample analysis' );
|
||||
$chart->set_x_axis( name => 'Test number' );
|
||||
$chart->set_y_axis( name => 'Sample length (mm)' );
|
||||
|
||||
# Set an Excel chart style. Colors with white outline and shadow.
|
||||
$chart->set_style( 10 );
|
||||
|
||||
# Insert the chart into the worksheet (with an offset).
|
||||
$worksheet->insert_chart( 'D2', $chart, 25, 10 );
|
||||
|
||||
__END__
|
||||
|
||||
|
||||
=begin html
|
||||
|
||||
<p>This will produce a chart that looks like this:</p>
|
||||
|
||||
<p><center><img src="http://jmcnamara.github.io/excel-writer-xlsx/images/examples/scatter1.jpg" width="483" height="291" alt="Chart example." /></center></p>
|
||||
|
||||
=end html
|
||||
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
John McNamara jmcnamara@cpan.org
|
||||
|
||||
=head1 COPYRIGHT
|
||||
|
||||
Copyright MM-MMXX, John McNamara.
|
||||
|
||||
All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
|
||||
315
database/perl/vendor/lib/Excel/Writer/XLSX/Chart/Stock.pm
vendored
Normal file
315
database/perl/vendor/lib/Excel/Writer/XLSX/Chart/Stock.pm
vendored
Normal file
@@ -0,0 +1,315 @@
|
||||
package Excel::Writer::XLSX::Chart::Stock;
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Stock - A class for writing Excel Stock charts.
|
||||
#
|
||||
# Used in conjunction with Excel::Writer::XLSX::Chart.
|
||||
#
|
||||
# See formatting note in Excel::Writer::XLSX::Chart.
|
||||
#
|
||||
# Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
|
||||
#
|
||||
# Documentation after __END__
|
||||
#
|
||||
|
||||
# perltidy with the following options: -mbl=2 -pt=0 -nola
|
||||
|
||||
use 5.008002;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Carp;
|
||||
use Excel::Writer::XLSX::Chart;
|
||||
|
||||
our @ISA = qw(Excel::Writer::XLSX::Chart);
|
||||
our $VERSION = '1.07';
|
||||
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# new()
|
||||
#
|
||||
#
|
||||
sub new {
|
||||
|
||||
my $class = shift;
|
||||
my $self = Excel::Writer::XLSX::Chart->new( @_ );
|
||||
$self->{_show_crosses} = 0;
|
||||
$self->{_hi_low_lines} = {};
|
||||
$self->{_date_category} = 1;
|
||||
|
||||
# Override and reset the default axis values.
|
||||
$self->{_x_axis}->{_defaults}->{num_format} = 'dd/mm/yyyy';
|
||||
$self->{_x2_axis}->{_defaults}->{num_format} = 'dd/mm/yyyy';
|
||||
$self->set_x_axis();
|
||||
$self->set_x2_axis();
|
||||
|
||||
# Set the available data label positions for this chart type.
|
||||
$self->{_label_position_default} = 'right';
|
||||
$self->{_label_positions} = {
|
||||
center => 'ctr',
|
||||
right => 'r',
|
||||
left => 'l',
|
||||
above => 't',
|
||||
below => 'b',
|
||||
# For backward compatibility.
|
||||
top => 't',
|
||||
bottom => 'b',
|
||||
};
|
||||
|
||||
bless $self, $class;
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_chart_type()
|
||||
#
|
||||
# Override the virtual superclass method with a chart specific method.
|
||||
#
|
||||
sub _write_chart_type {
|
||||
|
||||
my $self = shift;
|
||||
|
||||
# Write the c:stockChart element.
|
||||
$self->_write_stock_chart( @_ );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _write_stock_chart()
|
||||
#
|
||||
# Write the <c:stockChart> element.
|
||||
# Overridden to add hi_low_lines(). TODO. Refactor up into the SUPER class.
|
||||
#
|
||||
sub _write_stock_chart {
|
||||
|
||||
my $self = shift;
|
||||
my %args = @_;
|
||||
|
||||
my @series;
|
||||
if ( $args{primary_axes} ) {
|
||||
@series = $self->_get_primary_axes_series;
|
||||
}
|
||||
else {
|
||||
@series = $self->_get_secondary_axes_series;
|
||||
}
|
||||
|
||||
return unless scalar @series;
|
||||
|
||||
# Add default formatting to the series data.
|
||||
$self->_modify_series_formatting();
|
||||
|
||||
$self->xml_start_tag( 'c:stockChart' );
|
||||
|
||||
# Write the series elements.
|
||||
$self->_write_ser( $_ ) for @series;
|
||||
|
||||
# Write the c:dropLines element.
|
||||
$self->_write_drop_lines();
|
||||
|
||||
# Write the c:hiLowLines element.
|
||||
$self->_write_hi_low_lines() if $args{primary_axes};
|
||||
|
||||
# Write the c:upDownBars element.
|
||||
$self->_write_up_down_bars();
|
||||
|
||||
# Write the c:axId elements
|
||||
$self->_write_axis_ids( %args );
|
||||
|
||||
$self->xml_end_tag( 'c:stockChart' );
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# _modify_series_formatting()
|
||||
#
|
||||
# Add default formatting to the series data.
|
||||
#
|
||||
sub _modify_series_formatting {
|
||||
|
||||
my $self = shift;
|
||||
|
||||
my $index = 0;
|
||||
for my $series ( @{ $self->{_series} } ) {
|
||||
if ( $index % 4 != 3 ) {
|
||||
if ( !$series->{_line}->{_defined} ) {
|
||||
$series->{_line} = {
|
||||
width => 2.25,
|
||||
none => 1,
|
||||
_defined => 1,
|
||||
};
|
||||
}
|
||||
|
||||
if ( !$series->{_marker} ) {
|
||||
if ( $index % 4 == 2 ) {
|
||||
$series->{_marker} = { type => 'dot', size => 3 };
|
||||
}
|
||||
else {
|
||||
$series->{_marker} = { type => 'none' };
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
||||
__END__
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Stock - A class for writing Excel Stock charts.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
To create a simple Excel file with a Stock chart using Excel::Writer::XLSX:
|
||||
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
use strict;
|
||||
use Excel::Writer::XLSX;
|
||||
|
||||
my $workbook = Excel::Writer::XLSX->new( 'chart.xlsx' );
|
||||
my $worksheet = $workbook->add_worksheet();
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'stock' );
|
||||
|
||||
# Add a series for each High-Low-Close.
|
||||
$chart->add_series(
|
||||
categories => '=Sheet1!$A$2:$A$6',
|
||||
values => '=Sheet1!$B$2:$B$6'
|
||||
);
|
||||
|
||||
$chart->add_series(
|
||||
categories => '=Sheet1!$A$2:$A$6',
|
||||
values => '=Sheet1!$C$2:$C$6'
|
||||
);
|
||||
|
||||
$chart->add_series(
|
||||
categories => '=Sheet1!$A$2:$A$6',
|
||||
values => '=Sheet1!$D$2:$D$6'
|
||||
);
|
||||
|
||||
# Add the worksheet data the chart refers to.
|
||||
# ... See the full example below.
|
||||
|
||||
__END__
|
||||
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements Stock charts for L<Excel::Writer::XLSX>. The chart object is created via the Workbook C<add_chart()> method:
|
||||
|
||||
my $chart = $workbook->add_chart( type => 'stock' );
|
||||
|
||||
Once the object is created it can be configured via the following methods that are common to all chart classes:
|
||||
|
||||
$chart->add_series();
|
||||
$chart->set_x_axis();
|
||||
$chart->set_y_axis();
|
||||
$chart->set_title();
|
||||
|
||||
These methods are explained in detail in L<Excel::Writer::XLSX::Chart>. Class specific methods or settings, if any, are explained below.
|
||||
|
||||
=head1 Stock Chart Methods
|
||||
|
||||
There aren't currently any stock chart specific methods. See the TODO section of L<Excel::Writer::XLSX::Chart>.
|
||||
|
||||
The default Stock chart is a High-Low-Close chart. A series must be added for each of these data sources.
|
||||
|
||||
|
||||
=head1 EXAMPLE
|
||||
|
||||
Here is a complete example that demonstrates most of the available features when creating a Stock chart.
|
||||
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Excel::Writer::XLSX;
|
||||
use Excel::Writer::XLSX;
|
||||
|
||||
my $workbook = Excel::Writer::XLSX->new( 'chart_stock.xlsx' );
|
||||
my $worksheet = $workbook->add_worksheet();
|
||||
my $bold = $workbook->add_format( bold => 1 );
|
||||
my $date_format = $workbook->add_format( num_format => 'dd/mm/yyyy' );
|
||||
my $chart = $workbook->add_chart( type => 'stock', embedded => 1 );
|
||||
|
||||
|
||||
# Add the worksheet data that the charts will refer to.
|
||||
my $headings = [ 'Date', 'High', 'Low', 'Close' ];
|
||||
my $data = [
|
||||
|
||||
[ '2007-01-01T', '2007-01-02T', '2007-01-03T', '2007-01-04T', '2007-01-05T' ],
|
||||
[ 27.2, 25.03, 19.05, 20.34, 18.5 ],
|
||||
[ 23.49, 19.55, 15.12, 17.84, 16.34 ],
|
||||
[ 25.45, 23.05, 17.32, 20.45, 17.34 ],
|
||||
|
||||
];
|
||||
|
||||
$worksheet->write( 'A1', $headings, $bold );
|
||||
|
||||
for my $row ( 0 .. 4 ) {
|
||||
$worksheet->write_date_time( $row+1, 0, $data->[0]->[$row], $date_format );
|
||||
$worksheet->write( $row+1, 1, $data->[1]->[$row] );
|
||||
$worksheet->write( $row+1, 2, $data->[2]->[$row] );
|
||||
$worksheet->write( $row+1, 3, $data->[3]->[$row] );
|
||||
|
||||
}
|
||||
|
||||
$worksheet->set_column( 'A:D', 11 );
|
||||
|
||||
# Add a series for each of the High-Low-Close columns.
|
||||
$chart->add_series(
|
||||
categories => '=Sheet1!$A$2:$A$6',
|
||||
values => '=Sheet1!$B$2:$B$6',
|
||||
);
|
||||
|
||||
$chart->add_series(
|
||||
categories => '=Sheet1!$A$2:$A$6',
|
||||
values => '=Sheet1!$C$2:$C$6',
|
||||
);
|
||||
|
||||
$chart->add_series(
|
||||
categories => '=Sheet1!$A$2:$A$6',
|
||||
values => '=Sheet1!$D$2:$D$6',
|
||||
);
|
||||
|
||||
# Add a chart title and some axis labels.
|
||||
$chart->set_title ( name => 'High-Low-Close', );
|
||||
$chart->set_x_axis( name => 'Date', );
|
||||
$chart->set_y_axis( name => 'Share price', );
|
||||
|
||||
|
||||
$worksheet->insert_chart( 'E9', $chart );
|
||||
|
||||
__END__
|
||||
|
||||
=begin html
|
||||
|
||||
<p>This will produce a chart that looks like this:</p>
|
||||
|
||||
<p><center><img src="http://jmcnamara.github.io/excel-writer-xlsx/images/examples/stock1.jpg" width="483" height="291" alt="Chart example." /></center></p>
|
||||
|
||||
=end html
|
||||
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
John McNamara jmcnamara@cpan.org
|
||||
|
||||
=head1 COPYRIGHT
|
||||
|
||||
Copyright MM-MMXX, John McNamara.
|
||||
|
||||
All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
|
||||
|
||||
Reference in New Issue
Block a user