Excel-Writer-XLSX-CDF
view release on metacpan or search on metacpan
4950515253545556575859606162636465666768697071Set and returns the Y axis label of the Excel chart
Default: Probability
## chart\_x\_label
Set and returns the X axis label of the Excel chart
Default:
""
## chart\_legend\_display
Set and returns the legend display property
for
the Excel chart
Default: 1
## chart\_colors
Set and returns an array reference of Excel color codes to
use
for
each
CDF in group order. The
default
color once all colors are used is black.
Default: \[
'#FF0000'
,
'#800000'
,
'#FFFF00'
,
'#808000'
,
'#00FF00'
,
'#008000'
,
'#00FFFF'
,
'#008080'
,
'#0000FF'
,
'#000080'
,
'#FF00FF'
,
'#800080'
\]
## group\_names\_sort
lib/Excel/Writer/XLSX/CDF.pm view on Meta::CPAN
131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162=cut
sub chart_x_min {
my $self = shift;
$self->{'chart_x_min'} = shift if @_;
$self->{'chart_x_min'} = undef unless exists $self->{'chart_x_min'};
return $self->{'chart_x_min'};
}
=head2 chart_legend_display
Set and returns the legend display property for the Excel chart
Default: 1
=cut
sub
chart_legend_display {
my
$self
=
shift
;
$self
->{
'chart_legend_display'
} =
shift
if
@_
;
$self
->{
'chart_legend_display'
} = 1
unless
defined
$self
->{
'chart_legend_display'
};
return
$self
->{
'chart_legend_display'
};
}
=head2 chart_colors
Set and returns an array reference of Excel color codes to use for each CDF in group order. The default color once all colors are used is black.
Default: ['#FF0000', '#800000', '#FFFF00', '#808000', '#00FF00', '#008000', '#00FFFF', '#008080', '#0000FF', '#000080', '#FF00FF', '#800080']
=cut
lib/Excel/Writer/XLSX/CDF.pm view on Meta::CPAN
220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255#Open string scalar reference as file handle for Excel::Writer::XLSX to write to
open
my
$fh
,
'>'
, \
my
$content
or
die
(
"Error: Filehandle open error: $!"
);
#Object for Excel Workbook
require
Excel::Writer::XLSX;
my
$workbook
= Excel::Writer::XLSX->new(
$fh
);
#Add a worksheet chart as first tab so it shows when document is opened
my
$chart
=
$workbook
->add_chart(
type
=>
'scatter'
,
subtype
=>
'straight'
);
#Add worksheet for chart legend groups
my
$worksheet_groups
=
$workbook
->add_worksheet(
'groups'
);
$worksheet_groups
->write_string(0, 0,
'Group'
);
$worksheet_groups
->write_string(0, 1,
'Index'
);
$worksheet_groups
->write_string(0, 2,
'Count'
);
my
$group_index
= 0;
#Colors for data series lines and legend
my
@colors
= @{
$self
->chart_colors};
#foreach group add worksheet, data and chart series
my
@stats_groups
= ();
foreach
my
$group
(
@groups
) {
#Add series label for legend
$group_index
++;
$worksheet_groups
->write_string(
$group_index
, 0,
$group
);
$worksheet_groups
->write_number(
$group_index
, 1,
$group_index
);
#Add worksheet
my
$worksheet
=
$workbook
->add_worksheet(
"group_$group_index"
);
#Add data to worksheet
my
@values
=
sort
{
$a
<=>
$b
} @{
$series
->{
$group
}->{
'values'
}};
my
$values_count
=
scalar
(
@values
);
lib/Excel/Writer/XLSX/CDF.pm view on Meta::CPAN
304305306307308309310311312313314315316317318319320321322323
if
(!
defined
(
$minset
)) {
$minset
=
undef
;
#allow for calculation in the future
}
elsif
(
defined
(
$minset
) and
$minset
=~ m/\Aauto\Z/i) {
$minset
=
undef
;
}
#Configure chart
$chart
->set_title(
name
=>
$self
->chart_title );
$chart
->set_y_axis(
name
=>
$self
->chart_y_label,
min
=> 0 ,
max
=> 1 );
$chart
->set_x_axis(
name
=>
$self
->chart_x_label,
min
=>
$minset
,
max
=>
$maxset
);
$chart
->set_legend(
none
=> 1)
unless
$self
->chart_legend_display;
#Write Excel output to filehandle
$workbook
->
close
;
return
$content
;
}
=head2 generate_file
t/002_generate.t view on Meta::CPAN
10111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
skip
"Error: Cannot create a temp file. Read-only file system?"
, 4
unless
(
$tempdir
&& -d
$tempdir
&& -r
$tempdir
);
unlink
$tempdir
;
my
@data
=
map
{
[
one
=>
rand
],
[
two
=>
int
(10
*rand
)/10 ],
[
three
=>
int
(50
*rand
)/50 ],
} (1 .. 1000);
{
my
$e
= Excel::Writer::XLSX::CDF->new(
chart_title
=>
""
,
chart_x_label
=>
""
,
chart_y_label
=>
""
,
chart_legend_display
=>0);
my
$filename
=
$e
->generate_file(\
@data
);
ok(-r
$filename
,
'generate_file'
);
ok(-s
$filename
,
'generate_file'
);
diag(
"Created: $filename"
);
}
{
my
$e
= Excel::Writer::XLSX::CDF->new(
chart_title
=>
"My Title"
,
chart_x_label
=>
"My X Axis"
,
chart_y_label
=>
"My Y Axis"
,
chart_legend_display
=> 1,
chart_colors
=> [
'#EE1111'
,
'#11EE11'
,
'#1111EE'
],
group_names_sort
=> 1,
);
my
$filename
=
$e
->generate_file(\
@data
);
ok(-r
$filename
,
'generate_file'
);
ok(-s
$filename
,
'generate_file'
);
diag(
"Created: $filename"
);
}
{
my
$e
= Excel::Writer::XLSX::CDF->new(
chart_title
=>
"My Title"
,
chart_x_label
=>
"My X Axis"
,
chart_y_label
=>
"My Y Axis"
,
chart_legend_display
=> 1,
chart_colors
=> [
'#EE1111'
,
'#11EE11'
,
'#1111EE'
],
group_names_sort
=> 1,
chart_x_min
=> 0.4,
chart_x_max
=> 0.6,
);
my
$filename
=
$e
->generate_file(\
@data
);
ok(-r
$filename
,
'generate_file'
);
ok(-s
$filename
,
'generate_file'
);
diag(
"Created: $filename"
);
}
{
my
$e
= Excel::Writer::XLSX::CDF->new(
chart_title
=>
"My Title"
,
chart_x_label
=>
"My X Axis"
,
chart_y_label
=>
"My Y Axis"
,
chart_legend_display
=> 1,
chart_colors
=> [
'#EE1111'
,
'#11EE11'
,
'#1111EE'
],
group_names_sort
=> 1,
chart_x_min
=>
'auto'
,
chart_x_max
=>
'auto'
,
);
my
$filename
=
$e
->generate_file(\
@data
);
ok(-r
$filename
,
'generate_file'
);
ok(-s
$filename
,
'generate_file'
);
diag(
"Created: $filename"
);
}
{
my
@additional
=
map
{[
one
=>
$_
/10]} (-5 .. 15);
my
$e
= Excel::Writer::XLSX::CDF->new(
chart_title
=>
"My Title"
,
chart_x_label
=>
"My X Axis"
,
chart_y_label
=>
"My Y Axis"
,
chart_legend_display
=> 1,
chart_colors
=> [
'#EE1111'
,
'#11EE11'
,
'#1111EE'
],
group_names_sort
=> 1,
);
my
$filename
=
$e
->generate_file([
@data
,
@additional
]);
ok(-r
$filename
,
'generate_file'
);
ok(-s
$filename
,
'generate_file'
);
diag(
"Created: $filename"
);
}
}
( run in 0.517 second using v1.01-cache-2.11-cpan-49f99fa48dc )