Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

How do I print a canvas graphic ?

by gerry (Sexton)
on Oct 20, 2005 at 17:21 UTC ( [id://501744]=perlquestion: print w/replies, xml ) Need Help??

gerry has asked for the wisdom of the Perl Monks concerning the following question:

I've written a perl 5.8 client running on W2K that communicates with my perl server module running on each of my 3 Unix Boxes. Each Unix box is running the same C++ application and is set up for load balancing. My client connects via a socket to each box and receives back various statistics on the health of the application for each of the servers.

My perl client then takes the information and creates a canvas to graph the information on. I have been using a screen print utility to capture the graph and print it because I haven't been able to figure out how to print the graphic displayed on the canvas from within the perl module.

The graph I want to print is a typical XY Multi-Line Graph with text information around it. I have 2 arrays where each element in each array represents a minute in time for a 2400 clock - 1440 elements (24*60). Each element in array 1 contains the total number of Transactions processed in that minute of time. The other array is similar, but contains the total number of threads running.

I have looked at CPAN but have been unsuccessful in finding what I need.

Do you know of a way to do this? Is there some utility that I need? Is there a way to save the canvas or graphic in a format that some other graphics program can use?

Your help is greatly appreciated.

a humble perl neophyte

Replies are listed 'Best First'.
Re: How do I print a canvas graphic ?
by polettix (Vicar) on Oct 20, 2005 at 17:40 UTC
    Update: Ok, I misread your question. A look into the links is still worth your time, anyway, for the generation of graphics in well-known image formats.

    A look at the Graphics section in CPAN may enlighten you, especially the Chart family. Note that this is only a subset of what you can really do for graphics in Perl (I'm thinking about Image::Magick, which shouldn't be needed in your case).

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.
      I checked out CPAN like you suggested and the Chart::Plot and Chart::Plot::Canvas sounds promising. But it's too late to re-write it now.

      I was hoping there might be some way to just print the Canvas object that I created.

      Thanks for your help.

Re: How do I print a canvas graphic ?
by zentara (Archbishop) on Oct 21, 2005 at 10:45 UTC
    I don't mess around on windows, but here is how it is done on linux. The code is probably close. There is Win::Photo for Win32 now......see Tk::WinPhoto for ActiveState. And see Tk Screen and Canvas Screenshots

    If you want to try the postscript method on win32, here is how you do it.

    #!/usr/bin/perl use Tk; #to change the background color, edit the ps file # 0.000 0.000 0.000 setrgbcolor AdjustColor # fill $width = 800; $height = 500; my $main = MainWindow->new(); my $canvas = $main->Canvas( -width=>$width, -height=>$height, -backgro +und=>"black"); $canvas->pack( -expand=>1,-fill=>'both'); &create; $canvas->update; $main->update; $main->Button( -text => "Save", -command => [sub { $canvas->update; my @capture=(); my ($x0,$y0,$x1,$y1)=$canvas->bbox('all'); @capture=('-x'=>$x0,'-y'=>$y0,-height=>$y1-$y0,-width=>$x1-$x +0); $canvas -> postscript(-colormode=>'color', -file=>$0.'.ps', -rotate=>0, -width=>800, -height=>500, @capture); } ] )->pack; MainLoop; sub create{ $canvas->createOval(100, 100, 600, 600,-fill=>'green') }

    I'm not really a human, but I play one on earth. flash japh
      I'll check it out and see if it will accomplish the job. Thanks!
Re: How do I print a canvas graphic ?
by BrowserUk (Patriarch) on Oct 20, 2005 at 20:44 UTC
    My perl client then takes the information and creates a canvas ...

    What type of "canvas"? Is this a Tk::Canvas widget or something else?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
      Yes, it is a Scrolled Tk::Canvas as in

      $c = $mg->Scrolled("Canvas", -scrollbars => 'se', .....)

        Then you might consider using the postscript() method to output the canvas to a file and then send that to a postscript printer or use some .ps to .html or similar utility to do the printing.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://501744]
Approved by g0n
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-19 22:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found