in reply to Tk:: Graph menu not working to change the type of graph
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.
Robsub setdisplay { $typ = shift; $ca->configure(-type => $typ); $ca->redraw; }
|
|---|
| 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 | |
by rcseege (Pilgrim) on Sep 27, 2006 at 16:15 UTC |