1#!/usr/bin/perl 2 3############################################################################### 4# 5# Example of how to add sparklines to an Excel::Writer::XLSX file. 6# 7# Sparklines are small charts that fit in a single cell and are 8# used to show trends in data. See sparklines2.pl for examples 9# of more complex sparkline formatting. 10# 11# Copyright 2000-2021, John McNamara, jmcnamara@cpan.org 12# 13 14use strict; 15use warnings; 16use Excel::Writer::XLSX; 17 18my $workbook = Excel::Writer::XLSX->new( 'sparklines1.xlsx' ); 19my $worksheet = $workbook->add_worksheet(); 20 21# Some sample data to plot. 22my $data = [ 23 24 [ -2, 2, 3, -1, 0 ], 25 [ 30, 20, 33, 20, 15 ], 26 [ 1, -1, -1, 1, -1 ], 27 28]; 29 30# Write the sample data to the worksheet. 31$worksheet->write_col( 'A1', $data ); 32 33 34# Add a line sparkline (the default) with markers. 35$worksheet->add_sparkline( 36 { 37 location => 'F1', 38 range => 'Sheet1!A1:E1', 39 markers => 1, 40 } 41); 42 43# Add a column sparkline with non-default style. 44$worksheet->add_sparkline( 45 { 46 location => 'F2', 47 range => 'Sheet1!A2:E2', 48 type => 'column', 49 style => 12, 50 } 51); 52 53# Add a win/loss sparkline with negative values highlighted. 54$worksheet->add_sparkline( 55 { 56 location => 'F3', 57 range => 'Sheet1!A3:E3', 58 type => 'win_loss', 59 negative_points => 1, 60 } 61); 62 63$workbook->close(); 64 65__END__ 66