my $workbook = Excel::Writer::XLSX->new( 'chart.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 = [ @H ]
#my $data = [ @D ];
my $h = <CSV>;
chomp( $h);
my @H = split( ',', $h );
$worksheet->write( 0,0, \@H, $bold ); # write_row()
my $i = 1;
while( <CSV> )
{
chomp;
my @B = split( ',', $_ );
$worksheet->write( $i++, 0, \@B ); # write_row()
}
close( CSV );
# Create a new chart object. In this case an embedded chart.
my $chart = $workbook->add_chart( type => 'scatter',
subtype => 'stacked',
embedded => 1
);
$chart->set_size( width => 1020, height => 720 );
$chart->set_title ( name => 'NEXT: Near End Crosstalk',
name_font => { name => 'Calibri', #'Arial',
size => 22,
bold => 1,
#italic => 1,
},
);
$chart->set_x_axis( name => 'Frequncy (Hz)',
num_format => '#,##0',
min => 10,
max => 80000,
crossing => 0,
# position_axis => 'on_tick',
log_base => 10,
label_position => 'next_to',
major_tick_mark => 'outside',
minor_tick_mark => 'outside',
major_gridlines => {
visible => 1,
line => { color => '#E0E0E0',
width => 0.75,
dash_type => 'solid'
}
},
minor_gridlines => { visible => 1,
line => { color => '#E0E0E0',
width => 0.75,
dash_type => 'solid' }
},
name_font => { name => 'Calibri', #'Arial',
size => 14,
bold => 1,
#italic => 1,
}
);
$chart->set_y_axis( name => 'NEXT (DB)',
num_format => '0E+00', #'###0',
min => 0,
max => 2e-4,
# minor_unit => 0.4,
# major_unit => 2,
# interval_tick => 4,
major_tick_mark => 'outside',
minor_tick_mark => 'outside',
major_gridlines => { visible => 1,
line => { color => '#E0E0E0',
width => 0.75,
dash_type => 'solid' }
},
minor_gridlines => { visible => 1,
line => { color => '#E0E0E0',
width => 0.75,
dash_type => 'solid' }
},
name_font => { name => 'Calibri', #'Arial',
size => 14,
bold => 1,
}
);
$chart->set_legend( position => 'overlay_top_right', #'top_right',
fill => 'solidfill',
);
#$chart->set_legend({ 'font'=> { 'bold' => 1, 'italic' => 1}}); <<== t
+aken from CPAN example, it generates error
# Configure the first series.
$chart->add_series( name => '=Sheet1!$B$1',
categories => '=Sheet1!$A$2:$A$6701',
values => '=Sheet1!$B$2:$B$7701',
line => { #color => 'red',
width => 2.0
},
);
# Configure the first series.
$chart->add_series( name => '=Sheet1!$C$1',
categories => '=Sheet1!$A$2:$A$6701',
values => '=Sheet1!$C$2:$C$7701',
line => { #color => 'blue',
width => 2.0
},
);
# Configure the first series.
$chart->add_series( name => '=Sheet1!$D$1',
categories => '=Sheet1!$A$2:$A$6701',
values => '=Sheet1!$D$2:$D$7701',
line => { #color => 'magenta',
width => 2.0
},
);
# Configure the first series.
$chart->add_series( name => '=Sheet1!$E$1',
categories => '=Sheet1!$A$2:$A$6701',
values => '=Sheet1!$E$2:$E$7701',
line => { #color => 'cyan',
width => 2.0
},
);
# Set an Excel chart style. Blue colors with white outline and shadow.
$chart->set_style( 23 );
# Insert the chart into the worksheet (with an offset).
$worksheet->insert_chart( 'G2', $chart , 0, 0 ); ## last twp #s are X
+_offset, Y_offset
$workbook->close();
|