anna_black has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I'm using the Tk::Graph module to include a bar-chart in my application, with data that can be updated by the app. My problem is that I'm getting an error when the key for the data is 0. For example:

use Tk; use Tk::Graph; $mw = MainWindow->new; my $data = { 0 => 51, 2 => 135, -2 => 124, 4 => 5 }; my $graph = $mw->Graph(-type => 'BARS', -fill => 'both', -sortnames => 'num') ->pack(-expand => 1, -fill => 'both',); $graph->set($data); # set data MainLoop();

When I run this, I get the following error: ERROR in Tk::Graph:Tk::Graph::bar #666: No Name! at [...]/5.8.5/Tk/Graph.pm line 1802.

I tried to retrace the problem to the module's code, and found that it happens in the subroutine bar, that has the following line: my $name    = shift || return error('No Name!');

As far as I understand, when the name is 0, the code goes to the error, instead of displaying the bar. Is this an expected behaviour? Am I doing something wrong?

Incidentally, are there other modules that can be used in Tk to present charts?

Thanks a lot.

Replies are listed 'Best First'.
Re: Tk::Graph problem
by jethro (Monsignor) on Mar 31, 2009 at 13:26 UTC

    Looks to me like a bug, and a common one. Either patch your module, send a bug report to the module owner and/or use ' 0' (note the space before the 0) instead of 0.