help with GD module

Discussion in 'Perl Misc' started by abcd, Mar 2, 2009.

  1. abcd

    abcd Guest

    use GD::Graph::bars;
    my @data = (
    ['frogs','fish','toads','rodents'],
    [ 8, 3, 1, 2],
    );
    my $chart = GD::Graph::bars->new(700,500);
    $chart->set(title => 'Ostrich diet');
    $chart->set_title_font('arialbd', 24);
    $chart->set_x_axis_font('arial', 16);
    $chart->set_y_axis_font('arial', 16);
    my $gd_object = $chart->plot(\@data);


    but don't work, only open a cmd windown a nothing else!

    how I can create a window with graphics?
     
    abcd, Mar 2, 2009
    #1
    1. Advertising

  2. abcd

    zentara Guest

    On Mon, 2 Mar 2009 13:12:02 +0100, "abcd" <> wrote:

    >use GD::Graph::bars;
    >my @data = (
    >['frogs','fish','toads','rodents'],
    >[ 8, 3, 1, 2],
    >);
    >my $chart = GD::Graph::bars->new(700,500);
    >$chart->set(title => 'Ostrich diet');
    >$chart->set_title_font('arialbd', 24);
    >$chart->set_x_axis_font('arial', 16);
    >$chart->set_y_axis_font('arial', 16);
    >my $gd_object = $chart->plot(\@data);
    >
    >
    >but don't work, only open a cmd windown a nothing else!
    >
    >how I can create a window with graphics?
    >


    You can use Image Magick's display utility, or even easier, put the
    output in a Tk window.

    Example: (attention: Tk likes it's photo's base64 encoded )

    #!/usr/bin/perl -w
    use GD;
    use Tk;
    use Tk::pNG;
    use MIME::Base64;

    my $main = new MainWindow;
    my $photo_obj = $main->Photo(-data => get_graph() );

    my $display = $main->Label(-image => $photo_obj,
    )->pack(-fill=>'both', -expand=>1);

    $main->Button(-text => 'exit',
    -command => sub{exit}
    )->pack();


    MainLoop;

    sub get_graph{
    my $gd = GD::Image->new(400,300);
    my $white = $gd->colorAllocate(255, 255, 255);
    my $black = $gd->colorAllocate( 0, 0, 0);
    my $red = $gd->colorAllocate(255, 0, 0);
    my $green = $gd->colorAllocate( 0, 255, 0);
    my $blue = $gd->colorAllocate( 0, 0, 255);
    my $yellow = $gd->colorAllocate(255, 255, 0);

    $gd->filledRectangle(0, 129, 199, 169, $blue);

    my $poly = GD::polygon->new();
    $poly->addPt(199, 149);
    $poly->addPt(399, 74);
    $poly->addPt(324, 149);
    $poly->addPt(399, 224);
    $gd->filledPolygon($poly, $yellow);
    $gd->polygon ($poly, $black);
    $gd->arc(199, 149, 250, 250, 0, 360, $red);

    # Tk likes it's images base64encoded
    return encode_base64( $gd->png() );
    }

    __END__


    zentara

    --
    I'm not really a human, but I play one on earth.
    http://www.zentara.net/~zentaran/My_Petition_to_the_Great_Cosmic_Conciousness.html
     
    zentara, Mar 2, 2009
    #2
    1. Advertising

  3. abcd

    J. Gleixner Guest

    abcd wrote:
    > use GD::Graph::bars;
    > my @data = (
    > ['frogs','fish','toads','rodents'],
    > [ 8, 3, 1, 2],
    > );
    > my $chart = GD::Graph::bars->new(700,500);
    > $chart->set(title => 'Ostrich diet');
    > $chart->set_title_font('arialbd', 24);
    > $chart->set_x_axis_font('arial', 16);
    > $chart->set_y_axis_font('arial', 16);
    > my $gd_object = $chart->plot(\@data);
    >
    >
    > but don't work, only open a cmd windown a nothing else!


    Why would you expect it to display the image?

    >
    > how I can create a window with graphics?


    Use the Tk module or save it as a file and use a browser or some
    other application, such as a browser, to display it.
     
    J. Gleixner, Mar 2, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rh0dium
    Replies:
    2
    Views:
    356
    rh0dium
    Aug 4, 2005
  2. Maric Michaud
    Replies:
    0
    Views:
    7,222
    Maric Michaud
    Jun 24, 2006
  3. abcd
    Replies:
    4
    Views:
    266
    Ben Finney
    Mar 20, 2007
  4. Jonno
    Replies:
    0
    Views:
    111
    Jonno
    Feb 19, 2014
  5. Jonno
    Replies:
    0
    Views:
    86
    Jonno
    Feb 19, 2014
Loading...

Share This Page