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

发布于 2024-10-02 04:59:53 字数 165 浏览 0 评论 0原文

我有一个文本文件,我想将其输出为图表。文本文件看起来像这样 -

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

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

I have a text file that i would like to output as a graph. The text file looks something like this -

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

I would like to output it to a bar graph or a pie chart. What would the best way to do this be?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ペ泪落弦音 2024-10-09 04:59:53

或者你可以使用 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);
}

Or you could use 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);
}

太傻旳人生 2024-10-09 04:59:53

如果您想要实际图像,请使用 Chart::Pie (IIRC 它制作 GIF)- 该链接是 POD 中的使用示例。

同样的Chart包也有Chart::Bars 以及

If you want an actual image, use Chart::Pie (IIRC it maks GIFs) - the link is an example of usage in POD.

The same Chart package also has Chart::Bars as well

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文