Chart

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

    Added support for negative values in the datasets
    Added methods to remember and dump imagemap pixel information
    Included rgb.txt with distribution for WinXX users

0.93 - 0.94:
    Moved the legend down to be flush with the chart
    Fixed the long decimal y-tick label problem
    Fixed (for the last time, hopefully) the pre-5.004 compilation problem
    Fixed handling of undefined data points
    Added more colors for the default data colors
    Added the transparent gif option
    Added the option for user-specified colors
    Added the grid_lines option

0.92 - 0.93: 
    Fixed the sort problem
    Fixed the y-axis label centering problem
    Fixed pre-5.004 compilation problem
    Added StackedBars charts

lib/Chart/Base.pm  view on Meta::CPAN


    # let the points in Chart::Points and Chart::LinesPoints be 18 pixels wide
    $self->{'pt_size'} = 18;

    # use the old non-spaced bars
    $self->{'spaced_bars'} = 'true';

    # use the new grey background for the plots
    $self->{'grey_background'} = 'true';

    # don't default to transparent
    $self->{'transparent'} = 'false';

    # default to "normal" x_tick drawing
    $self->{'x_ticks'} = 'normal';

    # we're not a component until Chart::Composite says we are
    $self->{'component'} = 'false';

    # don't force the y-axes in a Composite chare to be the same
    $self->{'same_y_axes'} = 'false';

lib/Chart/Base.pm  view on Meta::CPAN

    return 1;
}

## @fn private int _set_colors
#  specify my colors
# @return status
sub _set_colors {
    my $self = shift;

    my $index = $self->_color_role_to_index('background');    # allocate GD color
    if ( $self->true( $self->{'transparent'} ) )
    {
        $self->{'gd_obj'}->transparent($index);
    }

    # all other roles are initialized by calling $self->_color_role_to_index(ROLENAME);

    # and return
    return 1;
}

## @fn private int _color_role_to_index
# return a (list of) color index(es) corresponding to the (list of) role(s)

lib/Chart/Base.pm  view on Meta::CPAN

    # get the appropriate brush size
    if ( $type eq 'line' ) {
        $radius = $self->{'brush_size'} / 2;
    } elsif ( $type eq 'point' ) {
        $radius = $self->{'pt_size'} / 2;
    }

    # create the new image
    $brush = GD::Image->new( $radius * 2, $radius * 2 );

    # get the colors, make the background transparent
    $white = $brush->colorAllocate( 255, 255, 255 );
    $newcolor = $brush->colorAllocate(@rgb);
    $brush->transparent($white);

    # draw the circle
    if ( $type eq 'line' ) {
        $brush->arc( $radius - 1, $radius - 1, $radius, $radius, 0, 360, $newcolor );
        $brush->fill( $radius - 1, $radius - 1, $newcolor );

        # RLD
        #
        # Does $brush->fill really have to be here?  Dunno... this
        # seems to be a relic from earlier code

lib/Chart/Base.pm  view on Meta::CPAN

            'OpenRectangle', 'fatPlus',            'Star',   'OpenStar',
            'FilledDiamond', 'OpenDiamond'
          );

        my ( $xc, $yc ) = ( $radius, $radius );

        if ( grep { $brushStyle eq $_ } ( 'default', 'circle', 'donut', 'OpenCircle', 'FilledCircle' ) ) {
            $brush->arc( $xc, $yc, $radius, $radius, 0, 360, $newcolor );
            $brush->fill( $xc, $yc, $newcolor );

            # draw a white (and therefore transparent) circle in the middle
            # of the existing circle to make the "donut", if appropriate

            if ( $brushStyle eq 'donut' || $brushStyle eq 'OpenCircle' )
            {
                $brush->arc( $xc, $yc, int( $radius / 2 ), int( $radius / 2 ), 0, 360, $white );
                $brush->fill( $xc, $yc, $white );
            }
        }

        if ( grep { $brushStyle eq $_ } ( 'triangle', 'upsidedownTriangle' ) ) {

lib/Chart/Direction.pm  view on Meta::CPAN

        $radius = $self->{'brush_size'} / 2;
    }
    elsif ( $type eq 'point' )
    {
        $radius = $self->{'pt_size'} / 2;
    }

    # create the new image
    $brush = GD::Image->new( $radius * 2, $radius * 2 );

    # get the colors, make the background transparent
    $white = $brush->colorAllocate( 255, 255, 255 );
    $newcolor = $brush->colorAllocate(@rgb);
    $brush->transparent($white);

    # draw the circle
    $brush->arc( $radius - 1, $radius - 1, $radius, $radius, 0, 360, $newcolor );

    # fill it if we're using lines
    $brush->fill( $radius - 1, $radius - 1, $newcolor );

    # set the new image as the main object's brush
    return $brush;
}

lib/Chart/ErrorBars.pm  view on Meta::CPAN

        $radius = $self->{'brush_size'} / 2;
    }
    elsif ( $type eq 'point' )
    {
        $radius = $self->{'pt_size'} / 2;
    }

    # create the new image
    $brush = GD::Image->new( $radius * 2, $radius * 2 );

    # get the colors, make the background transparent
    $white = $brush->colorAllocate( 255, 255, 255 );
    $newcolor = $brush->colorAllocate(@rgb);
    $brush->transparent($white);

    # draw the circle
    $brush->arc( $radius - 1, $radius - 1, $radius, $radius, 0, 360, $newcolor );

    # fill it if we're using lines
    $brush->fill( $radius - 1, $radius - 1, $newcolor );

    # set the new image as the main object's brush
    return $brush;
}

lib/Chart/Lines.pm  view on Meta::CPAN

    my $color  = shift;
    my $radius = $self->{'brush_size'} / 2;
    my ( @rgb, $brush, $white, $newcolor );

    # get the rgb values for the desired color
    @rgb = $self->{'gd_obj'}->rgb($color);

    # create the new image
    $brush = GD::Image->new( $radius * 2, $radius * 2 );

    # get the colors, make the background transparent
    $white = $brush->colorAllocate( 255, 255, 255 );
    $newcolor = $brush->colorAllocate(@rgb);
    $brush->transparent($white);

    # draw the circle
    $brush->arc( $radius - 1, $radius - 1, $radius, $radius, 0, 360, $newcolor );

    # set the new image as the main object's brush
    return $brush;
}

## be a good module and return 1
1;

lib/Chart/Manual/Properties.pod  view on Meta::CPAN

L</png_border> .......... L<pos_int|/"positive integer">: space between graph parts and image edge in pixel; C<10>

L</sub_title> ........... L</string>: text below the L</title> in smaller letters; C<''>

L</text_space> .......... L<pos_int|/"positive integer">: extra space around any text; C<2>

L</title> ............... L</string>: text on top of a chart; C<''>

L</title_font> .......... L</font> of the title text; GD::Font->Large

L</transparent> ......... L<bool|/boolean>: full image background transparency; C<'false'>

L</x_label> ............. L</string>: x-axis label text; C<''>

L</y_label> ............. L</string>:label on the standard, left y-axis; C<''>

L</y_label2> ............ L</string>:label on right y-axis, if different; C<''>


=head2 NoPie

lib/Chart/Manual/Properties.pod  view on Meta::CPAN


Content of title text. If empty, no title is drawn.  
It recognizes '\n' as a newline, and acts accordingly.
Remember, if you want to use normal quotation marks instead of single 
quotation marks then you have to quote "\\n". Default is empty.

=head2 title_font

This option changes the L</font> of the title. Default is GD::Font->Large.

=head2 transparent

Makes the background of the whole image transparent if set to C<'true'>.  
Useful for making web page images.  Default is C<'false'>.

=head2 x_grid_lines

Draws vertical grid lines matching up to x ticks if set to C<'true'>.
Default is C<'false'>.

=head2 x_label

Tells Chart what to use for the x-axis label.  If empty, no label

lib/Chart/Manual/Types.pod  view on Meta::CPAN

The class Chart::Mountain creates a mountain chart, which is a line chart
(see L</Lines>), where the area under the curve, right to the curve below
is filled with the color of the data set. In the following example we use
custom colors in hex notation (as supported by Chart::Color) which are 
getting mapped onto the colors settings of 
L<dataset0|Chart::Manual::Properties/colors-datasetx> .. dataset4.
As always, the first data set (row in the data table) holds the domain or
x-axis labels. Another specialty of mountain charts are patterns (not provided !),
to fill the area with. We load them via GD and give them over to the
C<'patterns'> property. Patterns are small images with one color and the
second being transparent.

    use Chart::Mountain;

    my @data = (
        ["1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th" ],
        [ 3, 7, 8, 2, 4  , 8.5, 2, 5, 9],
        [ 4, 2, 5, 6, 3  , 2.5, 3, 3, 4],
        [ 7, 3, 2, 8, 8.5, 2  , 9, 4, 5],
    );
    my @hex_colors = ('#0099FF', '#00CC00', '#EEAA00', '#FF0099','#3333FF');

lib/Chart/Mountain.pm  view on Meta::CPAN

            for ( $x_begin .. $x_end )
            {
                $poly->addPt( $x[$_], $y_ref->[$_] ) if defined $y_ref->[$_];
            }
        }

        # draw the polygon
        my $color = $self->_color_role_to_index( 'dataset' . $dataset );
        if ( $patterns[$dataset] )
        {
            $self->{'gd_obj'}->filledPolygon( $poly, $color ) if $patterns[$dataset]->transparent >= 0;
            $self->{'gd_obj'}->setTile( $patterns[$dataset] );
            $self->{'gd_obj'}->filledPolygon( $poly, gdTiled );
        }
        else
        {
            $self->{'gd_obj'}->filledPolygon( $poly, $color );
        }

        # delete previous dataset's points from the polygon, update $last_vertex_count.
        unless ( $dataset == 0 )

t/bars.t  view on Meta::CPAN


print "1..1\n";

$g = Chart::Bars->new( 600, 600 );
$g->add_dataset( 'foo', 'bar', 'junk', 'ding',  'bat' );
$g->add_dataset( 30000, 40000, 80000,  50000,   90000 );
$g->add_dataset( 80000, 60000, 30000,  30000,   40000 );
$g->add_dataset( 50000, 70000, 20200,  80000.8, 40000 );

%hash = (
    'transparent'  => 'true',
    'precision'    => 1,
    'title'        => 'Bars\nChartmodul',
    'y_grid_lines' => 'true',
    'graph_border' => '4',
    'min_val'      => '0',
    'text_space'   => '2',
    'sub_title'    => 'Untertitel',
    'x_label'      => 'X-Achse',
    'y_label'      => 'Y-Achse',
    'y_label2'     => 'Y-Achse2',

t/bars_11.t  view on Meta::CPAN

    include_zero    => 'true',

    # integer_ticks_only => 'true',
    legend         => 'none',
    png_border     => 4,
    precision      => 1,
    skip_int_ticks => 1000,
    text_space     => 3,
    title          => "Tickets",
    title_font     => GD::Font->Giant,
    transparent    => 'false',
    x_ticks        => 'vertical',
    y_axes         => 'both',
    y_label        => '# Tickets',
    x_label        => 'Date',
);

$g->png("$samples/bars_11.png");
print "ok 1\n";

exit(0);

t/bars_12.t  view on Meta::CPAN

    include_zero    => 'true',

    # integer_ticks_only => 'true',
    legend         => 'none',
    png_border     => 4,
    precision      => 1,
    skip_int_ticks => 1000,
    text_space     => 3,
    title          => "Tickets",
    title_font     => GD::Font->Giant,
    transparent    => 'false',
    x_ticks        => 'vertical',
    y_axes         => 'both',
    y_label        => '# Tickets',
    x_label        => 'Date',
);

$g->png("$samples/bars_11.png");
print "ok 1\n";

exit(0);

t/bars_6.t  view on Meta::CPAN


    #   min_val            => 0,
    #   include_zero       =>  'true',
    png_border     => 4,
    precision      => 1,
    skip_int_ticks => 1000,
    spaced_bars    => 'true',
    text_space     => 3,
    title          => "Tickets",
    title_font     => GD::Font->Giant,
    transparent    => 'false',
    x_ticks        => 'vertical',
    y_axes         => 'both',
    y_label        => '# Tickets',

    #    max_val            => 9000,
);

$g->png("$samples/bars_6.png");
print "ok 1\n";

t/bars_7.t  view on Meta::CPAN

    grey_background => 'false',
    grid_lines      => 'true',
    include_zero    => 'true',
    legend          => 'none',
    png_border      => 4,
    precision       => 9,
    spaced_bars     => 'true',
    text_space      => 3,
    title           => "Tickets",
    title_font      => GD::Font->Giant,
    transparent     => 'false',
    x_ticks         => 'vertical',
    y_axes          => 'both',
    y_label         => '# Tickets',
    x_label         => 'Date',
);

$g->png("$samples/bars_7.png");
print "ok 1\n";

exit(0);

t/bars_8.t  view on Meta::CPAN


    #  integer_ticks_only => 'true',
    legend     => 'none',
    png_border => 4,

    #    precision          => 27,
    #    skip_int_ticks     => 1.0e-27,
    text_space  => 3,
    title       => "Tickets",
    title_font  => GD::Font->Giant,
    transparent => 'false',
    x_ticks     => 'vertical',
    y_axes      => 'both',
    y_label     => '# Tickets',
    x_label     => 'Date',
);

$g->png("$samples/bars_8.png");
print "ok 1\n";

exit(0);

t/bars_9.t  view on Meta::CPAN

    include_zero    => 'true',

    # integer_ticks_only => 'true',
    legend         => 'none',
    png_border     => 4,
    precision      => 1,
    skip_int_ticks => 1000,
    text_space     => 3,
    title          => "Tickets",
    title_font     => GD::Font->Giant,
    transparent    => 'false',
    x_ticks        => 'vertical',
    y_axes         => 'both',
    y_label        => '# Tickets',
    x_label        => 'Date',
);

$g->png("$samples/bars_9.png");
print "ok 1\n";

exit(0);

t/hbars_2.t  view on Meta::CPAN

print "1..1\n";

$g = Chart::HorizontalBars->new( 500, 400 );
$g->add_dataset( 'Foo', 'bar', 'junk', 'ding', 'bat' );
$g->add_dataset( -4,    3,     -4,     -5.4,   -2 );
$g->add_dataset( 2.2,   10,    -3,     8,      3 );
$g->add_dataset( -10,   2,     4,      -3,     -3 );
$g->add_dataset( 7,     -5,    -3,     4,      7 );

%hash = (
    'transparent'  => 'true',
    'y_axes'       => 'both',
    'title'        => 'Horizontal Bars Demo',
    'y_grid_lines' => 'true',
    'x_label'      => 'x-axis',
    'y_label'      => 'y-axis',
    'y_label2'     => 'y-axis',
    'tick_len'     => '5',
    'x_ticks'      => 'vertical',
    'grid_lines'   => 'true',
    'colors'       => {

t/mapbars.t  view on Meta::CPAN

    imagemap           => 'true',
    legend             => 'bottom',
    legend_labels      => \@legend_keys,
    max_val            => 100,
    min_val            => 80,
    png_border         => 4,
    same_y_axes        => 'true',
    spaced_bars        => 'true',
    title              => "Yield 2004",
    text_space         => 5,
    transparent        => 'true',
    x_ticks            => 'vertical',
    integer_ticks_only => 'true',
    skip_int_ticks     => 5,
);

$Graph->png("$png_name");

my $imagemap_data = $Graph->imagemap_dump();

foreach my $ds ( 1 .. 1 )

t/mapcomp.t  view on Meta::CPAN

    imagemap           => 'true',
    legend             => 'bottom',
    legend_labels      => \@legend_keys,
    max_val            => 100,
    min_val            => 80,
    png_border         => 4,
    same_y_axes        => 'true',
    spaced_bars        => 'true',
    title              => "Yield 2004",
    text_space         => 5,
    transparent        => 'true',
    x_ticks            => 'vertical',
    integer_ticks_only => 'true',
    skip_int_ticks     => 5,
);

$Graph->png("$png_name");

#
my $imagemap_data = $Graph->imagemap_dump();



( run in 0.738 second using v1.01-cache-2.11-cpan-0a6323c29d9 )