in reply to Using Tk::Graph to graph two-dimensional data

Hi wishartz,

Please provide a more complete code example.  The subroutine you gave doesn't contain a closing brace "}", nor does it contain the closing brace for either of your foreach statements.

Since the problem you're having appears to be related to how much of the data is formatted for use by the Tk::Graph object, knowing the code to the end of the loops is fairly important.  You should also strongly consider reformatting your indentation to give visual clues about which code belongs in which block; without which your code is pretty difficult to follow.

I will take a guess, though, and assume that the loops both terminate past after the code you showed.  According to the CPAN documentation for Tk::Graph, an example of its usage is:

my $data = { Sleep => 51, Work => 135, Access => 124, mySQL => 5 }; my $ca = $mw->Graph( -type => 'BARS', )->pack( -expand => 1, -fill => 'both', ); $ca->configure(-variable => $data); # bind to data # or ... $ca->set($data); # set data

However, you appear to be calling Tk::Graph multiple times within your foreach loops, and each time assigning only a single pair of data (which I've reformatted here to make immensely more readable):

$data = { $queue => $usage }; $ca = $MW->Graph(-type => 'BARS', -ylabel => 'percentage', -xlabel + => 'queue'); $ca->pack(-expand => 1, -fill => 'both');

It would appear that a partial fix to your problem might involve moving the construction of the Tk::Graph object outside of the inner loop, and within the loop changing the assignment of $data to:

$data->{$queue} = $usage;

so as not to overwrite its previous key/value pairs.

If this doesn't get you past the problem, please consider submitting the entire subroutine.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Replies are listed 'Best First'.
Re^2:Fixed Using Tk::Graph to graph two-dimensional data
by wishartz (Beadle) on Sep 26, 2006 at 11:31 UTC
    Sorry about my messy code. The good news is $data->{$queue} = $usage; worked I was overwriting the contents each time. Thanks a lot for the help guys.