view release on metacpan or search on metacpan
lib/Excel/Writer/XLSX/Chart.pm view on Meta::CPAN
$self->{_title_name} = $name;
$self->{_title_formula} = $name_formula;
$self->{_title_data_id} = $data_id;
# Set the font properties if present.
$self->{_title_font} = $self->_convert_font_args( $arg{name_font} );
# Set the title layout.
$self->{_title_layout} = $self->_get_layout_properties( $arg{layout}, 1 );
# Set the title overlay option.
$self->{_title_overlay} = $arg{overlay};
# Set the no automatic title option.
$self->{_title_none} = $arg{none};
}
###############################################################################
#
# set_legend()
#
lib/Excel/Writer/XLSX/Chart.pm view on Meta::CPAN
else {
my $title;
if ( $title = $self->{_title_formula} ) {
$self->_write_title_formula(
$title,
$self->{_title_data_id},
undef,
$self->{_title_font},
$self->{_title_layout},
$self->{_title_overlay}
);
}
elsif ( $title = $self->{_title_name} ) {
$self->_write_title_rich(
$title,
undef,
$self->{_title_font},
$self->{_title_layout},
$self->{_title_overlay}
);
}
}
# Write the c:plotArea element.
$self->_write_plot_area();
# Write the c:legend element.
$self->_write_legend();
lib/Excel/Writer/XLSX/Chart.pm view on Meta::CPAN
#
# 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',
);
lib/Excel/Writer/XLSX/Chart.pm view on Meta::CPAN
# 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.
if ( $font ) {
$self->_write_tx_pr( $font );
}
$self->xml_end_tag( 'c:legend' );
lib/Excel/Writer/XLSX/Chart.pm view on Meta::CPAN
# Write the c:delete element.
$self->_write_delete( 1 );
$self->xml_end_tag( 'c:legendEntry' );
}
##############################################################################
#
# _write_overlay()
#
# Write the <c:overlay> element.
#
sub _write_overlay {
my $self = shift;
my $val = 1;
my @attributes = ( 'val' => $val );
$self->xml_empty_tag( 'c:overlay', @attributes );
}
##############################################################################
#
# _write_plot_vis_only()
#
# Write the <c:plotVisOnly> element.
#
sub _write_plot_vis_only {
lib/Excel/Writer/XLSX/Chart.pm view on Meta::CPAN
#
# Write the <c:title> element for a rich string.
#
sub _write_title_rich {
my $self = shift;
my $title = shift;
my $is_y_axis = shift;
my $font = shift;
my $layout = shift;
my $overlay = shift;
$self->xml_start_tag( 'c:title' );
# Write the c:tx element.
$self->_write_tx_rich( $title, $is_y_axis, $font );
# Write the c:layout element.
$self->_write_layout( $layout, 'text' );
# Write the c:overlay element.
$self->_write_overlay() if $overlay;
$self->xml_end_tag( 'c:title' );
}
##############################################################################
#
# _write_title_formula()
#
# Write the <c:title> element for a rich string.
#
sub _write_title_formula {
my $self = shift;
my $title = shift;
my $data_id = shift;
my $is_y_axis = shift;
my $font = shift;
my $layout = shift;
my $overlay = shift;
$self->xml_start_tag( 'c:title' );
# Write the c:tx element.
$self->_write_tx_formula( $title, $data_id );
# Write the c:layout element.
$self->_write_layout( $layout, 'text' );
# Write the c:overlay element.
$self->_write_overlay() if $overlay;
# Write the c:txPr element.
$self->_write_tx_pr( $font, $is_y_axis );
$self->xml_end_tag( 'c:title' );
}
##############################################################################
#
lib/Excel/Writer/XLSX/Chart.pm view on Meta::CPAN
=over
=item * C<name>
Set the name (title) for the chart. The name is displayed above the chart. The name can also be a formula such as C<=Sheet1!$A$1>. The name property is optional. The default is to have no chart title.
=item * C<name_font>
Set the font properties for the chart title. See the L</CHART FONTS> section below.
=item * C<overlay>
Allow the title to be overlaid on the chart. Generally used with the layout property below.
=item * C<layout>
Set the C<(x, y)> position of the title in chart relative units:
$chart->set_title(
name => 'Title',
overlay => 1,
layout => {
x => 0.42,
y => 0.14,
}
);
See the L</CHART LAYOUT> section below.
=item * C<none>
lib/Excel/Writer/XLSX/Chart.pm view on Meta::CPAN
$chart->set_legend( position => 'bottom' );
The default legend position is C<right>. The available positions are:
top
bottom
left
right
top_right
overlay_left
overlay_right
overlay_top_right
none
=item * C<border>
Set the border properties of the legend such as colour and style. See the L</CHART FORMATTING> section below.
=item * C<fill>
Set the fill properties of the legend such as colour. See the L</CHART FORMATTING> section below.
lib/Excel/Writer/XLSX/Chart/Pie.pm view on Meta::CPAN
#
# 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',
);
lib/Excel/Writer/XLSX/Chart/Pie.pm view on Meta::CPAN
# 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' );
}
t/chart/sub_write_legend.t view on Meta::CPAN
$chart->_write_legend();
is( $got, $expected, $caption );
###############################################################################
#
# Test the _write_legend() method.
#
$caption = " \tChart: _write_legend()";
$expected = '<c:legend><c:legendPos val="r"/><c:layout/><c:overlay val="1"/></c:legend>';
$chart = _new_object( \$got, 'Excel::Writer::XLSX::Chart' );
$chart->set_legend( position => 'overlay_right' );
$chart->_write_legend();
is( $got, $expected, $caption );
###############################################################################
#
# Test the _write_legend() method.
#
$caption = " \tChart: _write_legend()";
$expected = '<c:legend><c:legendPos val="l"/><c:layout/><c:overlay val="1"/></c:legend>';
$chart = _new_object( \$got, 'Excel::Writer::XLSX::Chart' );
$chart->set_legend( position => 'overlay_left' );
$chart->_write_legend();
is( $got, $expected, $caption );
###############################################################################
#
# Test the _write_legend() method.
#
$caption = " \tChart: _write_legend()";
t/chart/sub_write_legend.t view on Meta::CPAN
$chart->_write_legend();
is( $got, $expected, $caption );
###############################################################################
#
# Test the _write_legend() method.
#
$caption = " \tChart: _write_legend()";
$expected = '<c:legend><c:legendPos val="tr"/><c:layout/><c:overlay val="1"/></c:legend>';
$chart = _new_object( \$got, 'Excel::Writer::XLSX::Chart' );
$chart->set_legend( position => 'overlay_top_right' );
$chart->_write_legend();
is( $got, $expected, $caption );
__END__
t/regression/chart_layout03.t view on Meta::CPAN
];
$worksheet->write( 'A1', $data );
$chart->add_series( values => '=Sheet1!$A$1:$A$5' );
$chart->add_series( values => '=Sheet1!$B$1:$B$5' );
$chart->add_series( values => '=Sheet1!$C$1:$C$5' );
$chart->set_legend(
position => 'overlay_right',
layout => {
x => 0.80197353455818043,
y => 0.3744240303295423,
width => 0.12858202099737534,
height => 0.25115157480314959,
}
);
$worksheet->insert_chart( 'E9', $chart );
t/regression/chart_layout06.t view on Meta::CPAN
];
$worksheet->write( 'A1', $data );
$chart->add_series( values => '=Sheet1!$A$1:$A$5' );
$chart->add_series( values => '=Sheet1!$B$1:$B$5' );
$chart->add_series( values => '=Sheet1!$C$1:$C$5' );
$chart->set_title(
name => 'Title',
overlay => 1,
layout => {
x => 0.42354155730533688,
y => 0.16203703703703703,
}
);
$worksheet->insert_chart( 'E9', $chart );
$workbook->close();
t/regression/chart_layout08.t view on Meta::CPAN
];
$worksheet->write( 'A1', $data );
$chart->add_series( values => '=Sheet1!$A$1:$A$5' );
$chart->add_series( values => '=Sheet1!$B$1:$B$5' );
$chart->add_series( values => '=Sheet1!$C$1:$C$5' );
$chart->set_title(
name_formula => '=Sheet1!$A$1', data => [1],
overlay => 1,
layout => {
x => 0.359652668416448,
y => 0.16203703703703703,
}
);
$worksheet->insert_chart( 'E9', $chart );
$workbook->close();
t/regression/chart_legend04.t view on Meta::CPAN
[ 3, 6, 9, 12, 15 ],
];
$worksheet->write( 'A1', $data );
$chart->add_series( values => '=Sheet1!$A$1:$A$5' );
$chart->add_series( values => '=Sheet1!$B$1:$B$5' );
$chart->add_series( values => '=Sheet1!$C$1:$C$5' );
$chart->set_legend( position => 'overlay_top_right' );
$worksheet->insert_chart( 'E9', $chart );
$workbook->close();
###############################################################################
#
# Compare the generated and existing Excel files.
#
t/regression/chart_pie04.t view on Meta::CPAN
];
$worksheet->write( 'A1', $data );
$chart->add_series(
categories => '=Sheet1!$A$1:$A$3',
values => '=Sheet1!$B$1:$B$3',
);
$chart->set_legend( position => 'overlay_right' );
$worksheet->insert_chart( 'E9', $chart );
$workbook->close();
###############################################################################
#
# Compare the generated and existing Excel files.
#