I tried out Tk with GD somewhile back on linux, but ended up using a web server due to the access required. Here are a couple of snippets for you from my hacking around. I made this work by having GD output to a png file, and then with Tk presenting that file. The modules used were: Tk, Tk::PNG, and GD::Graph using the area format (GD::Graph::area). First making a graph with GD:
##### build a cpu graph... $poop = 'CPU - Wait IO data from '.$startdate.' - '.$enddate; # a fancy title for our graph @data = (\@dateline, \@graphcpu_usr, \@graphcpu_sys, \@graphcpu_wio ); + # this is an array of arrays. The first one is the X axis + # which is the time, the others are the Y axis my $data = GD::Graph::Data->new() or die GD::Graph::Data->error; $data->copy_from(\@data); + # this tells the graph to get the data from the data array my $my_graph = new GD::Graph::area(400,300); + # and this says what type (area) and it's size $my_graph->set( + # and set up all the particulars... r_margin => 1, x_label => 'Time', y_label => 'CPU Utilization', title => $poop, y_min_value => 0, y_tick_number => 8, y_label_skip => 1, x_ticks => 1, x_label_skip => $x_label_skip, x_labels_vertical => 1, x_label_position => 1/2, cumulate => 1, transparent => 1, )or warn $my_graph->error; open (IMG, ">dbcpu.png") or die "Can't open up the dpcpu graph file"; binmode IMG; $my_graph->set( dclrs => [ qw(lgreen lblue lred) ] ); + # here is the colors in the graph $my_graph->set_legend("usr","sys","wio" ); + # and the legend text $my_graph->set_title_font(GD::Font->MediumBold); print IMG $my_graph->plot($data)->png(); + # and this plots the image out to a png format close IMG;
And here is where in TK the graph is displayed:
$fr = $mw->Frame(-relief => 'groove', -borderwidth => 5)->pack( -side => 'left', -expand => 1 ); # the canvas has scroll bars and we sized the viewable part at 625x800 $canvas = $fr->Scrolled('Canvas', -height => 625, -width =>800,)->pack( -side => 'right', -expand => 1 ); # here we define the cpu graph and where we find it $dbcpu = $canvas->Photo(-format => 'png', -file => '/home/mjacobs/scripts/perl/dbcpu.png', -palette => '16/16/16'); # and this actually puts the image on the canvas $dbcpu_gr = $canvas->createImage(300,250, -image => $dbcpu, -tags => "dbcpu", -anchor => "center");

In reply to Re: Using GD on MS Windows by odha57
in thread Using GD on MS Windows by SparkyEE

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.