Term::Chart - Create attractive bar charts for the terminal interface.
my $tc = Term::Chart->new(); $tc->add_values(map { $_**2 } 1 .. 9); print "$tc\n";
my $tc = Term::Chart->new( { orientation => 'vertical', style => 'dot', border => 1, tip => "\x{29BF}", } ); my @values = 0 .. 8; push @values, reverse 0 .. 7; for my $n (@values) { my %datum = ( value => $n, label => $n, ); $tc->add_value( \%datum ); } print "$tc\n";
my $tc = Term::Chart->new( { orientation => 'horizontal', border => 1, bar => "\x{2015}", tip => "\x{29BF}", color_range => [ 160 .. 165 ], } ); for my $n (qw( 0 1 2 3 4 5 6 5 4 3 2 1 0 )) { my %datum = ( value => $n, label => "label $n", ); $tc->add_value( \%datum ); } print "$tc\n";
my $tc = Term::Chart->new( { orientation => 'vertical', tip => 'x', color_range => [ 160 .. 165 ], } ); for my $n (qw( 0 1 2 3 4 5 6 5 4 3 2 1 0 )) { my %datum = ( value => $n, label => $n, ); $tc->add_value( \%datum ); } print "$tc\n";
my $tc = Term::Chart->new( { border => 2 } ); for ( 0 .. 2 ) { for my $n (qw( 0 1 2 3 2 1 0 )) { $tc->add_value( { value => $n**2 } ); } } print "$tc\n";
my $tc = Term::Chart->new( { border => 0, color_range => [ 172 .. 177 ], } ); for ( 0 .. 2 ) { for my $n (qw( 0 1 2 3 2 1 0 )) { $tc->add_value( { value => $n**2 } ); } } print "$tc\n";
This module offers you a convenient way to create bar & dot charts and for your command line programs.
The charts can include ANSI color markup and Unicode drawing characters.
The constructor accepts a hash ref with the following optional parameters.
The character used for the bars. The default is U+2585 for horizontal, and U+2589 for vertical.
The last character on each bar, at the tip. The default is U+2585 for horizontal, and U+2589 for vertical.
The row height. Default is determined at run time by the Term::ReadKey module.
The column width. Default is determined at run time by the Term::ReadKey module.
Pass an array ref with a range (0 to 255) of color values which will be used accross each bar. The default is no colors at all.
Either 'dot' or 'bar'. Default is 'bar'.
Either 'vertical' or 'horizontal'. Default is 'horizontal'.
0 is no border, 1 to 255 to indicate the color of the border. The default is 0.
Add a value to be graphed. Accepts a hash ref with:
The optional text label.
The numeric value being charted. (If a non-numeric value is supplied, then its string length will be used as the value.)
Add a list of values (without labels) all at once.
This will print the rendered chart to STDOUT.
Dylan Doxey, <dylan@cpan.org>
Copyright (C) 2017 by Dylan Doxey
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.2 or, at your option, any later version of Perl 5 you may have available.
To install Term::Chart, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Term::Chart
CPAN shell
perl -MCPAN -e shell install Term::Chart
For more information on module installation, please visit the detailed CPAN module installation guide.