in reply to Tk:: Graph menu not working to change the type of graph

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

Replies are listed 'Best First'.
Fixed:Re^2: Tk:: Graph menu not working to change the type of graph
by wishartz (Beadle) on Sep 27, 2006 at 16:07 UTC
    I managed to get it fixed by putting
    $ca->configure(-variable => $data);
    in my subdisplay function, below the line
    $ca->configure(-type => $typ);
    and it seems to work. Thanks for everybody's help.

      Yep, under the hood that will also call the set method. The advantage of using variable is that if you update your data, then the changes should be reflected automatically within your Graph.

      Rob