timeseries/tsplotv

52 lines
1.2 KiB
Plaintext
Raw Normal View History

#!/usr/bin/perl -w
=head1 NAME
tsplotv - plot time series given in vertical format
=head1 DESCRIPTION
This program expects time series data in vertical format, I.e.,
each line contains a tripel <time, series, value>.
=cut
use strict;
use TimeSeries;
use Getopt::Long;
my $output_format ='png';
my $stacked = 0;
my $legend_position = 'top right';
GetOptions('output_format|output-format=s' => \$output_format,
'stacked' => \$stacked,
'legend_position|legend-position=s' => \$legend_position,
) or die "Usage: $0 [--output_format format] [files...]\n";
binmode STDOUT, ':raw';
my %series;
my $ns;
my %data;
my $ts = TimeSeries->new(output_format => $output_format);
while (<>) {
chomp;
my ($timestamp, $series, $value) = split(/\t/);
$series{$series} = ++$ns unless ($series{$series});
$data{$timestamp}{$series} = $value;
}
my @series = sort { $series{$a} <=> $series{$b} } keys %series;
$ts->legend(@series);
$ts->legend_position($legend_position);
$ts->stacked($stacked);
for my $timestamp (sort keys %data) {
my %d = %{$data{$timestamp}};
my @values = @d{@series};
$ts->add_timestring($timestamp, @values);
}
my $g = $ts->plot();
print $g