Here is a basic Tk::Canvas script to do it. You can do what ever you want in the callback. I just print the x,y position, and the x axis label.
#!/usr/bin/perl use warnings; use strict; use Tk; my $w=20; my $x=0; my $y=0; my %colors = ( 0 => ['black','yellow'], 1 => ['yellow','black'], 2 => ['green','white'], 3 => ['lightgreen','white'], 4 => ['grey','red'], 5 => ['red','grey'], 6 => ['lightsteelblue','white',], 7 => ['blue','white',], 8 => ['orange','grey45'], 9 => ['grey45','orange'], ); my %bardata = ( 0 => 100 + rand 200, 1 => 100 +rand 200, 2 => 100 +rand 200, 3 => 100 +rand 200, 4 => 100 +rand 200, 5 => 100 +rand 200, 6 => 100 +rand 200, 7 => 100 +rand 200, 8 => 100 +rand 200, 9 => 100 +rand 200, ); my %bars; my $mw=tkinit; my $c = $mw->Canvas(-bg=>'white')->pack(-expand=>1,-fill=>'both'); foreach my $key(sort keys %bardata) { $bars{$key} = $c->createRectangle($x,$y,$x+20,$bardata{$key}, -fill=> ${$colors{$key}}[0], -tags=>[ $key] ); my $text = $c->createText($x+10,$y+10, -anchor=>'center', -fill => ${$colors{$key}}[1], -text => $key ); $x+=20; } $mw->Button( -text => "Save", -command => [sub { $c->update; my @capture=(); my ($x0,$y0,$x1,$y1)=$c->bbox('all'); @capture=('-x'=>$x0,'-y'=>$y0,-height=>$y1-$y0,-width=>$x1-$x +0); $c -> postscript(-colormode=>'color', -file=>$0.'.ps', -rotate=>90, -width=>800, -height=>500, @capture); } ] )->pack; $c->Tk::bind("<Button-1>", [ \&print_xy, Ev('x'), Ev('y') ]); # adjust canvas size to show all my ($x0,$y0,$x1,$y1)=$c->bbox('all'); $c->configure( -width=>($x1-$x0)+20, -height=>($y1-$y0)+20 ); MainLoop; ########################################################## sub print_xy { #print "@_\n"; my ($canv, $x, $y) = @_; print "(x,y) = ", $canv->canvasx($x), ", ", $canv->canvasy($y), "\t" +; my $current = $canv->find(qw/withtag current/); my (@tags) = $canv->gettags($current); print "for @tags\n\n"; }

I'm not really a human, but I play one on earth Remember How Lucky You Are

In reply to Re^2: Graphics Module by zentara
in thread Graphics Module by KianTern

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.