The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

  Tk::LineGraph - A 2D Plot widget written entirely in Perl/Tk.

DESCRIPTION

The LineGraph widget is an extension of the Canvas widget that will plot Dataset objects in a 2D graph. It is written entirely in Perl/Tk. Scaled labeled X, Y and Y1 axis are displayed. Many Datasets can be displayed in one LineGraph widget. The widget is interactive allowing the plot to be zoomed and individual data sets to be shown or hidden. Axis scales and labels can be set in the code and interactively. Indeed almost all the LineGraph options can be changed from the widget itself. LineGraph is a quick easy way to build an interactive Plot widget into a Perl application.

The following additional (in addition to the Canvas options) option/value pairs are supported:

-dataset

A data set to be given to the LineGraph widget to be plotted. No default.

-colors

An array of colors to use for the display of the data sets. If there are more data sets than colors in the array then the colors will cycle.

-boarders

An array of four numbers which are the boarder size in pixels of the plot in the canvas. The order is North (top), East (right), South (bottom) and West (right). These values can be changed from the PlotSetup Menu.

-scale

A nine element array of the scale factors for the x,y, and y1 axis. The nine values are xMin, Xmax, xStep, yMin, yMax, yStep, y1Min, y1Max, and y1Step. The plot can be rescaled by changing these values. This can be done in code using the configure method or using the Axis Menu. The default values for all the axis are 0 to 100 with a step size of 10.

-plotTitle

A two element array. The first element is the plot title, the second element is the y offset of the title below the top edge of the window. The title is centered in the x direction. These values can be changed from the PlotSetup Menu or the configure method.

-xlabel

The label for the X axis. The text is centered on the X axis. This value can be changed from the Axis Menu or the configure method.

-ylabel

The label for the Y axis. The text is centered on the Y axis. This value can be changed from the Axis Menu. or the configure method.

-y1label

The label for the Y1 axis which is the optional axis to the right of the plot. The text is centered on the Y1 axis. This value can be changed from the Axis Menu. the configure method.

-xType

The type of the X axis. Currently only linear is supported for the X axis.

-yType

The type of the Y axis. Allowed values are linear and log. This value can be changed from the Axis Menu or the configure method. The default type is linear.

-y1Type

The type of the y1 axis. Allowed values are linear and log.. This value can be changed from the Axis Menu or the configure method.

-fonts

A four element array with the font names for the various labels in the plot. Element 0 is the font of the numbers at the axis ticks. Element 1 is the font for the axis labels (all of them), Element 2 is the plot title font and element 3 is the font for the legend. These values can be changed from the PlotSetup Menu or the configure method.

-autoScaleX

When set to "On" the X axis will be scaled to the values to be plotted. Default is "On". "Off" is the other possible value.

-autoScaleY

When set to "On" the Y axis will be scaled to the values to be plotted. Default is "On". "Off" is the other possible value.

-autoScaleY1

When set to "On" the Y1 axis will be scaled to the values to be plotted. Default is "On". "Off" is the other possible value.

WIDGET BEHAVIOR

When the cursor is on a plotted line the line turns red to help identify that line in the plot. Likewise when the cursor is over a Dataset name in the legend the corresponding dataset line plot will turn red. Individual points are not shown when there are more than 20 points in the plot.

The left button (button-1) is used to zoom a graph. Move the cursor to one of the corners of the box into which you want the graph to zoom. Hold down the left button and move to the opposite corner. Release the left button and the graph will zoom into the box. To undo one level of zoom click the left button without moving the mouse.

The center button can be used to see the coordinates of a point on the plot. With the cursor in the graph body click the center button and a pop up will show the coordinates of the cursor position scaled to the axis. The popup goes away when the center button is released.

The right button can be used to move a line on the plot. This can be useful in trying to line up date or move clutter.

The options menu provides tools to help look at the data. The Hide/Show option allows datasets to be removed from the plot, made "inactive". The same menu can make the dataset active. The Rescale Active option is used to rescale the graph to the currently active datasets. Again this can be useful in looking at selected datasets.

The Datasets option allows the color of a dataset to be changed. The vertical axis used to scale the dataset can be set from the Datasets menu. Finally the values in a Dataset can be displayed in the Datasets menu.

EXAMPLE

     use Tk;
     use LineGraph;
     use DataSet;

     my $mw = MainWindow->new;

     my $cp = $mw->LineGraph(-width=>500, -height=>500, -background => snow)->grid;

     my @yArray = (1..5,11..18,22..23,99..300,333..555,0,0,0,0,600,600,600,600,599,599,599);
     my $ds = LineGraphDataset->new(-yData=>\@yArray,-name=>"setOne");
     $cp->plot(-dataset=>$ds);

     MainLoop;

METHODS

addDatasets(-dataset=$ds1, -dataset=>$ds2, option=>value, )>
plot(-dataset=$ds4, option=>value, )>

AUTHOR

Tom Clifford (Still_Aimless@yahoo.com)

Copyright (C) Tom Clifford. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

BUGS

Case where the number of points in x and y are different is not handled. Log plot with zero or negative numbers is not graceful.

KEYWORDS

Plot 2D Axis

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 2145:

'=item' outside of any '=over'

Around line 2151:

You forgot a '=back' before '=head1'