File: sparklines1.pl

package info (click to toggle)
libexcel-writer-xlsx-perl 0.79-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,716 kB
  • ctags: 930
  • sloc: perl: 18,380; makefile: 40
file content (63 lines) | stat: -rw-r--r-- 1,425 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/perl

###############################################################################
#
# Example of how to add sparklines to an Excel::Writer::XLSX file.
#
# Sparklines are small charts that fit in a single cell and are
# used to show trends in data. See sparklines2.pl for examples
# of more complex sparkline formatting.
#
# reverse ('(c)'), November 2011, John McNamara, jmcnamara@cpan.org
#

use strict;
use warnings;
use Excel::Writer::XLSX;

my $workbook  = Excel::Writer::XLSX->new( 'sparklines1.xlsx' );
my $worksheet = $workbook->add_worksheet();

# Some sample data to plot.
my $data = [

    [ -2, 2,  3,  -1, 0 ],
    [ 30, 20, 33, 20, 15 ],
    [ 1,  -1, -1, 1,  -1 ],

];

# Write the sample data to the worksheet.
$worksheet->write_col( 'A1', $data );


# Add a line sparkline (the default) with markers.
$worksheet->add_sparkline(
    {
        location => 'F1',
        range    => 'Sheet1!A1:E1',
        markers  => 1,
    }
);

# Add a column sparkline with non-default style.
$worksheet->add_sparkline(
    {
        location => 'F2',
        range    => 'Sheet1!A2:E2',
        type     => 'column',
        style    => 12,
    }
);

# Add a win/loss sparkline with negative values highlighted.
$worksheet->add_sparkline(
    {
        location        => 'F3',
        range           => 'Sheet1!A3:E3',
        type            => 'win_loss',
        negative_points => 1,
    }
);

__END__