寻找一种将文本文件中的数据表示为图形的方法

时间:2010-11-14 14:13:01

标签: perl command-line vbscript batch-file

我有一个文本文件,我想以图表的形式输出。文本文件看起来像这样 -

Item 1
---
        1234
Item2
---
      5678
Item3
----
      910112

我想将其输出到条形图或饼图。最好的方法是什么?

2 个答案:

答案 0 :(得分:1)

或者您可以使用GD :: Graph

use strict;
use GD::Graph::bars;
use GD::Graph::hbars;
use GD::Graph::Data;

#For some reason, installing GD::Graph didn't put save.pl in my @INC path
require "/usr/share/doc/libgd-graph-perl/examples/samples/save.pl";

my $data = GD::Graph::Data->new([
    ["Item 1","Item 2","Item 3"],
    [1234, 5678, 910112],
    ]) or die GD::Graph::Data->error;

my @names = qw/GDbars123 GDbars123-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);
}

答案 1 :(得分:0)

如果你想要一个实际的图像,使用Chart::Pie(IIRC它可以作为GIF) - 该链接是POD中使用的一个例子。

同样的Chart package也有Chart::Bars