NAME

Fl::Chart - Display Simple Chart Data

Synopsis

use Fl qw[:color];
my $win = Fl::Window->new(1000, 480);
my $chart
    = Fl::Chart->new(20, 20, $win->w() - 40, $win->h() - 40, 'Chart');
$chart->bounds(-125, 125);
for (my $t = 0; $t < 15; $t += 0.5) {
    my $val = sin($t) * 125.0;
    $chart->add($val,
                sprintf('%-.1f', $val),
                ($val < 0) ? FL_RED : FL_GREEN);
}
$win->resizable($win);
$win->show();
exit Fl::run();

Description

Fl::Chart can display data in one of several formats. The following are imported from Fl with the :chart tag.

Methods

Fl::Chart is a subclass of Fl::Widget but also supports these methods:

new(...)

The constructor creates a chart of a given size and position on screen or within the parent.

my $chart_a = Fl::Chart->new(100, 150, 300, 500);

...or...

my $chart_b = Fl::Chart->new(100, 150, 300, 500, 'Daily Volume');

In these examples, the new chart is placed 100 pixels from the left and 150 pixels down from the top of either the display area or parent widget.

The default boxtyle is FL_NO_BOX.

The destructor also deletes all data.

add(...)

$chart->add(60, 'March 13, 2016', FL_RED);
$chart->add(64.3);

Add the data value with optional label and color to the chart.

autosize(...)

$chart->autosize(1);
my $resizing = $chart->autosize();

Get whether the chart will automatically adjust bounds of the chart. Returns non-zero if the chart will automatically resize.

bounds(...)

my ($upper, lower) = $chart->bounds();
$chart->bounds(100, -100);

Gets or sets the lower and upper bounds of the char values

clear()

$chart->clear();

Removes all values from the chart.

insert(...)

$chart->insert(1, 60, 'March 13, 2016', FL_RED);
$chart->insert(2, 64.3);

Inserts a value at the given position. Position 1 is the first data value.

maxsize(...)

$chart->maxsize(200);
my $limit = $chart->maxsize();

Gets or sets the maximum number of data values for a chart.

If you don't call this method, the chart will be allowed to grow to any size depending on available memory.

replace(...)

$chart->replace(1, 60, 'March 13, 2016', FL_RED);
$chart->replace(2, 64.3);

Replaces a value at the given position. Position 1 is the first data value.

size()

my $sample_size = $chart->size();

Returns the number of data points in the chart.

textcolor(...)

$chart->textcolor(FL_BLACK);
my $color = $chart->textcolor();

Gets or sets the chart's text color.

textfont(...)

$chart->textfont(FL_COURIER_BOLD);
my $font = $chart->textfont();

Gets or sets the chart's font.

textsize(...)

$chart->textsize(100);
$chart->textsize(FL_NORMAL_SIZE);

Sets the chart's text size.

LICENSE

Copyright (C) Sanko Robinson.

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

AUTHOR

Sanko Robinson <sanko@cpan.org>