Here is one way, using the example that comes with the module:
use Tk; use Tk::Graph; my $mw = MainWindow->new; my $data = { Sleep => 51, Work => 135, Access => 124, mySQL => 5 }; my $ca = $mw->Graph( -title => 'Example', -type => 'BARS' )->pack(qw/-expand 1 -fill both/); $ca->set($data); $mw->Button(-text => 'Change', -command => sub { $ca->configure(-type => 'Circle'); $ca->set($data); })->pack; MainLoop;

Update: The suggestion to use redraw was a good one -- that should work, but there is a bug within Graph.pm. The redraw method calls set with no value - the implication is that if no data is provided then the existing data should be used, however that is not what happens, and ultimately results in the display not getting redrawn. The workaround I provided will work. I'll report the bug and send the patch to the Author.

Within the set method, there is the following line:

   my $data = shift;.

If you change this to:

   my $data = shift || $self->{data};

Then redraw will work as you'd expect, and would support the following version of your setdisplay sub.

sub setdisplay { $typ = shift; $ca->configure(-type => $typ); $ca->redraw; }
Rob

In reply to Re: Tk:: Graph menu not working to change the type of graph by rcseege
in thread Tk:: Graph menu not working to change the type of graph by wishartz

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.