#!/usr/bin/perl -w # # A mixed stock graph use strict; use GD; use GD::Graph::Data; use GD::Graph::mixed; # Read in the data from a file my $data = GD::Graph::Data->new(); $data->read(file => 'stock_data.dat') or die "Couldn't read data!"; my $graph = new GD::Graph::mixed(900, 300) or die "Can't create graph!"; # Set the general attributes $graph->set( title => "Shemp Corp. stock 2002", types => [qw(area area bars)], dclrs => [qw(red white blue)], transparent => 0, ); # Set the attributes for the x-axis $graph->set( x_label => 'Day of Year', x_label_skip => 5, x_labels_vertical => 1, ); $graph->set( y_max_value => ($data->get_min_max_y_all())[1]+25, y_tick_number => 10, y_all_ticks => 1, y_number_format => sub { '$'.int(shift); }, ); # Set the legend $graph->set_legend(undef, undef, 'Volume is in thousands of shares traded'); $graph->set_legend_font(gdLargeFont); $graph->set(legend_placement => 'BL'); # Plot the data my $gd = $graph->plot( $data ) or die "Can't plot graph"; my $logo = GD::Image->newFromPng('shempcorp.png'); my ($w, $h) = $logo->getBounds(); $gd->copy($logo, 50, 25, 0, 0, $w, $h); # Write the PNG print $gd->png();