Name

plot( ) — generate a GIF from data

Synopsis

GIFgraph::plot(\@data)

The plot( ) method will take a data set, plot it according to the type of graph object and the values of the attributes that have been set, and return a scalar containing the GIF data. This function is used most often for plotting a graphic to STDOUT in CGI applications. Note that the data set is passed as a list of references to arrays; the first array in the list represents the values for the x axis, and each array after that represents a different set of y values to be plotted. For example, the following data will generate a graph with the month names on the x axis and two sets of numbers plotted against the y axis:

@data = (
        [ qw(JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC) ],
        [ 5,  8,  24,  32,  12,  18,  11,  21,  22,  9,  29,  16 ],
        [ 6.5,  12.8,  31.7,  3,  9,  15,  14.8,  21.2,  7,  9.9, 10,  7.2 ]
        );
$graph->plot(\@data);

If the arrays are not set up correctly (if, for example, the arrays are not all the same length), Perl will complain with a “length misfit” error. The data sets may be padded with undef values if the values are not to be plotted.

Get Programming Web Graphics with Perl and GNU Softwar now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.