NAME

Tk::Graph - A graphical Chartmaker at Canvas (Realtime).

SYNOPSIS

use Tk;
use Tk::Graph; 

$mw = MainWindow->new;

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 

MainLoop;

DESCRIPTION

A graphical Chartmaker at Canvas (Realtime). This is a real Canvas widget, so you can draw with the standard routines in the Canvas object. For example, you can draw a line with $chart->line(x,y,...). This is useful for you when you will add a logo or write some text in your created Chart.

WIDGET-SPECIFIC OPTIONS

-debug [0|1]

This is the switch for debug output at the normal console (STDOUT)

-type (Automatic, Line, Bars, HBars, Circle)

This is the type of Graph to display the data.

Automatic - analyze the datahash and choose a Chart:

Hash with values -> PieChart 
Hash with keys with hashes or values (not all) -> Barchart per Key 
Hash with keys with arrays -> Linechart per Key 
Array -> Linechart 

Line - Linechart,

Bars - Barchart with vertical Bars,

HBars - Barchart with horizontal bars,

Circle - PieChart

-foreground (black)

Color for the Axis, Legend and Labels.

-title -titlecolor (brown)

Message at the top of the Widget.

-headroom (20)

The headroom in percent. This is a clean area at the top of the widget. When a value is in this area, the graph is redrawn to preserve this headroom.

-max

Maximum Value for the axis. If this set, the axis is not dynamically redrawn to the next maximum value from the data. Only used in Lines and Bars!

-sortnames ('alpha' | 'num') -sortreverse (0, 1)

sort the keys from the data hash.

-config (\%cfghash)

A config hash with optional added parameters for more flexibility. The first is the name of the key from your data hash, followed by a config hash with parameters. example:

-config         => {
	'fr' => {
		-title => 'Free',
		-color => 'green',
	},
        'sl' => {
        	-title => 'Sleep',
        	-color => 'yellow',
        },
        ...
},

-title

Here you can write another Name to display.

-color

Key name displayed in this color.

-fill ('both')

The same as in perl/tk pack. Redraw only in x,y or both direction(s).

-xlabel -ylabel (text)

This displays a description for x and y axis.

-xtick -ytick (5)

Number of ticks at the x or y axis.

-xformat ('%s') -yformat ('%g')

This if the sprintf format for display of the value or key for the axis. example:

-xformat => '%d%%'      # This will eg. Display '50%'
-yformat => '%s host'   # This will eg. Display 'first host'

-padding ([15,20,20,50])

Margin display from the Widget border, in this order top, right, bottom, left.

-linewidth (1)

The weight of the border for the dots, circle and lines.

-printvalue

This is the sprintf format and switch for display of the value.

-maxmin

Draw max/average/min value lines in Bars and Line charts

-legend [0|1]

Switch on/off the legend in Circle or Lines

-colors (red, green, ...)

A comma-separated list with the allowed colors.

-shadow ('gray50') -shadowdepth (0)

You can add a shadow to all Charts, the switch is -shadowdepth. This is also the depth in Pixels for the shadow. -shadow is the color for the shadow.

-wire ('white')

Switch on/off a wire grid in background from line and bars chart.

-reference ('name', 'value')

This give a Reference value for the keys in datahash. I.e. the data values are displayed relative to this reference value.

example:

-reference      => 'Free, 1024',        # Free space at host

-look ('count')

The number of values to display in a line chart. When you refresh the data hash (maybe with the methods set or variable), then this will display eg. the last 50 values.

example:

-look   => 50,  # 50 values to display pro key

-dots ('width')

The width and switch for the dots in line chart.

-barwidth (30)

The width for bars in bar charts.

-balloon (0|1)

Switch on/off ballon help for segements or lines. The text format is used from the -printvalue option.

-font ('-*-Helvetica-Medium-R-Normal--*-100-*-*-*-*-*-*')

Draw text in this font.

-lineheight (15)

The line height in pixels for text in the legend.

METHODS

Here come the methods that you can use with this Widget.

$chart->set($data);

Set the data hash to display.

$chart->variable($data);

Bind the data hash to display the data, write to $data will redraw the widget.

$chart->redraw();

Redraw chart

$chart->redraw();

Clear the canvas.

EXAMPLES

Please see for examples in 'demos' directory in this distribution.

AUTHOR

Frank Herrmann xpix@netzwert.ag http://www.netzwert.ag

SEE ALSO

Tk, Tk::Trace, Tk::Canvas,