将图形打印到终端。 Perl的

时间:2014-07-02 10:32:04

标签: perl graph module

我刚刚找到了GD :: Graph模块,但它将图形打印到文件中。

我想创建一种在终端上打印的监视器。

例如,如何在终端上打印图形(不完全,但类似于适合终端)?

更新

use strict;
use GD::Graph::bars;
use GD::Graph::hbars;
use GD::Graph::Data;
require 'save.pl';

my $data = GD::Graph::Data->new([
    ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
    [    1,    2,    5,    6,    3,  1.5,    1,     3,     4],
]) or die GD::Graph::Data->error;

my @names = qw/sample11 sample11-h/;

for my $my_graph (GD::Graph::bars->new, GD::Graph::hbars->new)
{
    my $name = shift @names;

    print STDERR "Processing $name\n";

    $my_graph->set(
        x_label         => 'X Label',
        y_label         => 'Y label',
        title           => 'A Simple Bar Chart',
        #y_max_value     => 8,
        #y_tick_number   => 8,
        #y_label_skip    => 2,

        #x_labels_vertical => 1,

        # shadows
        bar_spacing     => 8,
        shadow_depth    => 4,
        shadowclr       => 'dred',

        transparent     => 0,
    )
    or warn $my_graph->error;

    $my_graph->plot($data) or die $my_graph->error;
    save_chart($my_graph, $name);
}

3 个答案:

答案 0 :(得分:3)

嗯,将图形打印到STDOUT很简单。您不必调用save_chart(),而只需执行以下操作:

print $my_graph->png;

但是,您的显示器不太可能理解抛出的原始PNG数据。您需要将绘图写入图像文件并以某种方式显示文件。

但如果不了解更多关于你想要做什么的话,很难提供帮助。

答案 1 :(得分:1)

您可以尝试hbar并根据需要进行修改:

https://github.com/xxfelixxx/perl-term-colormap/blob/master/bin/hbar

  echo '
     1  one
     1  one
     2  two
     5  five
     8  eight
     13 thirteen
     21 twenty one
  ' | hbar

hbar e

答案 2 :(得分:0)

你能用Graph :: Easy做你需要的吗?

Graph::Easy - Convert or render graphs (as ASCII, HTML, SVG or via
Graphviz)