PDF-Reuse-OverlayChart
view release on metacpan or search on metacpan
OverlayChart.pm view on Meta::CPAN
###################################
my $costs = PDF::Reuse::OverlayChart->new();
$costs->columns( qw(Month January February Mars April May June July));
$costs->add( qw(Riga -316 -290 -376 -823 -243 -320 -509));
$costs->add( qw(Helsinki -440 -830 -989 -671 -170 -394 -618));
$costs->add( qw(Stockholm -218 -345 -242 -467 -412 -299 -590));
$costs->add( qw(Oslo -369 -343 -567 -589 -390 -258 -459));
$costs->draw(x => 45,
y => 55,
yUnit => '1000 Euros',
type => 'bars',
title => 'Costs',
height => 300,
width => 460);
####################################
# The costs are added to 'money in'
####################################
$s->add( qw(Riga -316 -290 -376 -823 -243 -320 -509));
$s->add( qw(Helsinki -440 -830 -989 -671 -170 -394 -618));
$s->add( qw(Stockholm -218 -345 -242 -467 -412 -299 -590));
$s->add( qw(Oslo -369 -343 -567 -589 -390 -258 -459));
prPage();
$s->draw(x => 45,
y => 455,
yUnit => '1000 Euros',
type => 'bars',
title => 'Profit');
########
# Taxes
########
$s->add( qw(Riga -116 -90 -179 -230 -43 -20 -90));
$s->add( qw(Helsinki 40 -130 -190 -32 -70 -30 -18));
$s->add( qw(Stockholm 28 -45 -42 -107 -92 -99 -90));
$s->add( qw(Oslo -169 -43 -67 -189 -190 -58 -59));
$s->draw(x => 45,
y => 55,
yUnit => '1000 Euros',
type => 'bars',
title => 'After Tax');
prEnd();
=for end
=head1 An example how to mix different graph types in the same chart
In this example you let a program collect historical quotes for 'Amazon', approximately
1 year back, and also values for 'S&P 100' and then you get a chart with combined
data, an area graph for volumes, and lines for the other values. (You need to have the
environment variable TZ defined somewhere, see Date::Manip, which is a module needed by
Finance::QuoteHist. TZ, time zone, could e.g. be CET or GMT in Western Europe.)
=for overlay.pl begin
use PDF::Reuse::OverlayChart;
use Finance::QuoteHist;
use PDF::Reuse;
use strict;
#################
# Some variables
#################
my (%values, @values, %volumes, @volumes, %sp100, @sp100, $startValue,
$startSpValue);
my $maxVolume = 0;
my $maxValue = 0;
my $month = sprintf("%02d", ((localtime())[4]) + 1);
my $lastYear = sprintf("%04d", ((localtime())[5] + 1900 - 1));
my $aYearAgo = "$month/01/$lastYear";
prFile('myFile.pdf');
prCompress(1);
###########################################################
# Get historical quotes via the web for Amazon and S&P100
###########################################################
my $q = Finance::QuoteHist->new ( symbols => [qw(AMZN ^OEX)],
start_date => $aYearAgo,
end_date => 'today',);
##################################
# Accumulate the values in hashes
##################################
for my $row ($q->quotes())
{ my ($symbol, $date, $open, $high, $low, $close, $volume) = @$row;
if ($date =~ m'(\d+\/\d+)\/(\d+)'o)
{ my $yearMonth = $1;
my $day = $2;
if ($symbol ne '^OEX')
{ $volume = sprintf("%.0f", ($volume / 1000000));
$values{$yearMonth}->[$day] = $close if ($close);
$volumes{$yearMonth}->[$day] = $volume if ($volume);
$maxVolume = $volume if $volume > $maxVolume;
$maxValue = $close if $close > $maxValue;
$startValue = $close if (! defined $startValue);
}
else
{ $sp100{$yearMonth}->[$day] = $close if ($close);
$startSpValue = $close if (!defined $startSpValue);
}
}
}
my @keys = sort (keys %volumes);
my $i;
##########################################
# Make one array of arrays of the volumes
( run in 0.984 second using v1.01-cache-2.11-cpan-39bf76dae61 )